47
\$\begingroup\$

Print 0 to 100 without using characters 1,2,3,4,5,6,7,8,9 in your code.

Seperator of numbers can be comma, whitespace or newline.

Shortest code wins.

\$\endgroup\$
6
  • 12
    \$\begingroup\$ Many tricks are made possible by allowing 0. Which is what makes this challenge interesting, IMO. \$\endgroup\$
    – Arnauld
    Feb 23 at 17:08
  • 2
    \$\begingroup\$ I thought "do X without Y" questions weren't allowed anymore. \$\endgroup\$
    – Purple P
    Feb 24 at 3:34
  • 1
    \$\begingroup\$ @PurpleP They're allowed, but discouraged. Interesting ones are fine. \$\endgroup\$ Feb 25 at 0:06
  • 10
    \$\begingroup\$ Is there a requirement to stop printing at 100? \$\endgroup\$
    – spuck
    Feb 25 at 16:44
  • \$\begingroup\$ Can we do it in reverse order? \$\endgroup\$
    – Dion
    Oct 16 at 9:51

127 Answers 127

3
\$\begingroup\$

Shakespeare Programming Language, 218 bytes

,.Puck,.Ajax,.Act I:.Scene I:.[Exeunt][Enter Puck and Ajax]Puck:Open heart.You is the sum ofyou a cat.Ajax:You is twice the sum ofa big big cat a cat.Speak mind!You is the square ofyou.Is I nicer you?If notlet usAct I.

Try it online!

This is a golfed version based off of Dr Lemniscate's answer, with several non-trivial modifications, such as using only one Scene and not initialising characters. This also includes the character and program introduction section, which was neglected.

Explanation

,.Puck,.Ajax,.Act I:.Scene I:.     # Introduce the characters and the play itself.
[Exeunt][Enter Puck and Ajax]      # Enter the main characters
Puck: Open heart.                  # Print Ajax's value as a number
      You is the sum ofyou a cat.  # And increment it
Ajax: You is twice the sum ofa big big cat a cat.      # Set Puck to 2*(8+2)=10
      Speak mind!                  # Print as a character (a newline)
      You is the square ofyou.     # Square the value to 100
      Is I nicer you?              # Compare the value against Ajax's
      If notlet usAct I.           # And loop if the value is <= 100
\$\endgroup\$
3
\$\begingroup\$

JavaScript (V8), 52 39 bytes

for(i=0;!print(i)>=~-(''+i++).length;);

Try it online!

Thanks Jo king

Original version :

JavaScript (V8), 52 48 bytes

for(i=0;i<=(c="    ".length)*-~c*-~c;)print(i++)

Try it online!

Not the shortest by any margin

Explanation :

for(i = 0; // simple for loop 
    i <= (c="    ".length)*~-c*~-c;
        // c = "    ".length ---> 4 
        // * -~c * -~c       ---> -~c => 5 => 4 * * 5 * 5 ==> 100
        ;)print(i++)          ---> end for loop and print i, then increment by 1  

Alternately :

JavaScript (V8), 47 bytes

_=>[...Array((c="    ".length)*-~c*-~c).keys()]

Try it online!

That prints up to 99 for 51 bytes,

_=>[...Array((c="     ".length)**~-~-c-c*c).keys()]

Prints upto 100 but byte count is 54.

\$\endgroup\$
0
3
\$\begingroup\$

C, 53 bytes

int main(a,b){for(;a^'f';a++){printf("%d\n",a-!!a);}}

Try it online!

43 42 bytes

(Thanks to Jo King♦)

k;main(){for(;k^'e';)printf("%d ",k++);}

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Welcome to code golf, and nice first answer! Make sure to check out our tips for golfing in C to see if there's any way for you to shorten your code. \$\endgroup\$ Oct 29 at 13:37
3
\$\begingroup\$

PICO-8, 50 45 bytes

i=0-#"0"repeat i+=#"0"?i
until#tostr(i)>#"00"

-5 bytes by replacing print with its shorthand, ?.

Demo (50 byte version; 45 byte version has same output):

i=0-#"0"repeat i+=#"0"print(i)until#tostr(i)>#"00"

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Glad to see some PICO-8 on CGCC! It's such a fun little engine to tinker around with. \$\endgroup\$ Nov 3 at 8:50
3
\$\begingroup\$

AWK, 35 34 31 bytes

END{for(i;i<=0xA**2;)print i++}

Try it online!

-1 byte thanks to me

-3 bytes thanks to @cnamejj

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can remove the i=0 statement since AWK uses an initial value of 0 for any variable use in a mathematical expression before it's set. \$\endgroup\$
    – cnamejj
    Nov 8 at 8:53
  • 1
    \$\begingroup\$ And 0xA**2 saves another byte. (I tried to edit the previous comment but wasn't able too since more than 5 mins had passed.) \$\endgroup\$
    – cnamejj
    Nov 8 at 9:00
3
\$\begingroup\$

APL (Dyalog), 19 bytes

⎕←0,⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬

Try it here!

≢⍬⍬⍬⍬ ⍝ This evaluates to 4
≢⍬⍬ ⍝ This evaluates to 2

⍳≢⍬⍬⍬⍬ ⍝ Evaluates to 1 2 3 4
(+/⍳≢⍬⍬⍬⍬) ⍝ Sums up previous list, 1+2+3+4 = 10
(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Exponentiates previous result by 2
⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Generates 1 2 ... 100
0,⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Appends to 0 to front
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Nov 9 at 20:23
2
\$\begingroup\$

CJam, 6 bytes

'ei,:p

Try it online!

How it works

'e    e# Push character "e" (which has code point 101)
i     e# Convert to integer. Gives 101
,     e# Range (non-inclusive, starting at 0). Gives [0 1 2 ... 100]
:p    e# For each entry: print with newline
\$\endgroup\$
2
\$\begingroup\$

Pyth, 9, 8, 5 bytes

@hakr46's solution

Uh*TT

Try it online!


original:

U+*TT^Z

Try it online!

Outputs a list. If the separator must be a single character, 11 bytes 6 bytes

My first golf. Pretty happy about it! Makes use of the fact that anything to the power of 0 is 1.

-3/5 bytes thanks to @hakr46 :D

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Pyth has an increment instruction, h. Also, separating a list by newlines is done with j with only one argument. These let you save 3 bytes to output the list or 5 bytes to output each number with a single character separator. \$\endgroup\$
    – hakr14
    Feb 23 at 18:25
  • 1
    \$\begingroup\$ pyth.herokuapp.com's interpreter doesn't work anymore, but it still has searchable documentation, so I like to keep it open when golfing Pyth. \$\endgroup\$
    – hakr14
    Feb 23 at 18:27
  • \$\begingroup\$ thanks @hakr14! \$\endgroup\$ Feb 23 at 19:18
  • 1
    \$\begingroup\$ @hakr14 May I introduce you to pythtemp.herokuapp.com Interpreter that works WITH documentation \$\endgroup\$
    – Scott
    Feb 26 at 0:43
  • \$\begingroup\$ @Scott :O thank you so much... \$\endgroup\$
    – hakr14
    Feb 26 at 1:12
2
\$\begingroup\$

F# (.NET Core), 35 bytes

Seq.iter(printfn"%A"){0..(int 'd')}

Try it online!

(Too bad it wasn't only to 99, could have gotten rid of the Seq.iter due to printing truncation...)

\$\endgroup\$
2
\$\begingroup\$

BRASCA, 9 bytes

Hr,n[lon]

Try it online!

Explanation

Hr         - Push range(0,100)
  ,        - Reverse stack
   n       - Print the 0
    [   ]  - While not zero:
     lon   -    Print a newline and the next number
\$\endgroup\$
2
\$\begingroup\$

PHP, 29 bytes

<?=join(',',range(0,ord(d)));

Explanation

ord(d) // return integer value of ASCII character 'd'
range  // create array from A to B, inclusive
join   // glue array values together using comma as separator
<?=    // output

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 35 bytes

f(i){printf("%d ",i)&'#'?f(++i):0;}

Try it online!

Let's go recursively!

\$\endgroup\$
3
  • \$\begingroup\$ Function submission had to be reusable. So invoke f() the second time should print 0~100 again. \$\endgroup\$
    – tsh
    Feb 25 at 10:45
  • \$\begingroup\$ Would somebody smarter than me explain how this knows to stop counting? \$\endgroup\$ Feb 25 at 16:04
  • \$\begingroup\$ @MichaelStern - printf returns the number of characters printed - when we print 100, it returns 3. '#' is ASCII 35. 3 & 35 == false; This would work with any power of 2 value + 3 (lowest 2 bits set) - 3, 7, 11, 19, 35, 67, 131, etc. So, 'C' would also work. \$\endgroup\$ Feb 25 at 19:18
2
\$\begingroup\$

Tcl, 38 bytes

puts 0
time {puts [incr i]} [incr u]00

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Unfortunately it is not 1 to 100. I could do it even cheaper: tio.run/##K0nO@f@/JDM3VaG6oLSkWCE6My@5SCEzthbKKo01MPj/HwA \$\endgroup\$
    – sergiol
    Feb 25 at 20:12
  • \$\begingroup\$ I was about to suggest the code from your comment plus a lame puts 0. Still shorter. \$\endgroup\$
    – manatwork
    Feb 25 at 20:18
  • \$\begingroup\$ @manatwork: Yes it is shorter, thanks. \$\endgroup\$
    – sergiol
    Feb 25 at 20:23
2
\$\begingroup\$

T-SQL, 65 64 bytes

SELECT number FROM spt_values WHERE number<ASCII('e')AND'P'=type

The master database on any SQL server contains a system table called spt_values that (among other things) contain the numbers 0 to 2047. To cap the output I used ASCII('e'), which is 101.

Let me know if you know of a shorter way to generate the number 100 or 101.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Can't ) touch the AND keyword just as ' touches it? Because rewriting the expression as number<ASCII('e')AND'P'=type could save 1 character. \$\endgroup\$
    – manatwork
    Feb 25 at 21:17
  • \$\begingroup\$ Yep, that rearrangement works, @manatwork. Thanks! \$\endgroup\$
    – BradC
    Feb 25 at 21:27
2
\$\begingroup\$

Java (JDK), 71 bytes

v->java.util.stream.IntStream.range(0,'e').forEach(System.out::println)

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ 48 bytes \$\endgroup\$ Feb 25 at 17:41
  • \$\begingroup\$ Also, you answer as it is is neither a full program, a function nor a lambda, so it's actually invalid. \$\endgroup\$ Feb 25 at 17:44
  • \$\begingroup\$ Ah that's how java answers are considered? thanks \$\endgroup\$
    – Cray
    Feb 26 at 6:17
  • \$\begingroup\$ Well, then make a full program, a function or a lambda instead, and your answer will become valid and will be upvoted. An example is the first comment I gave, which uses a for-loop. You might want to check it out to see how we use lambdas here \$\endgroup\$ Feb 26 at 8:13
  • 1
    \$\begingroup\$ Because it's a lambda. Lambdas can be used as .doSomething(v->{...}). So the Type name = form i not specific to the lambda. What is specific to the lambda is the param -> ..., hence the wide usage of lambdas in Java answers here on codegolf. \$\endgroup\$ Feb 26 at 9:57
2
\$\begingroup\$

Erlang (escript), 42 bytes


main([])->io:write(lists:seq(0,hd("d"))).

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript Browser, 37 characters

alert([...Array(0xB0F-0xAAA).keys()])

But Arnaulds(https://codegolf.stackexchange.com/users/58563/arnauld) idea would be the faster way for browser js too (28)

for(n=0;n+n<0xCA;)alert(n++)
\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! Nice first answer. I've never seen that trick with .keys() before! \$\endgroup\$ Feb 27 at 21:49
  • \$\begingroup\$ @RedwolfPrograms, so you missed EliteDaMyth's solution? \$\endgroup\$
    – manatwork
    Feb 27 at 22:17
  • \$\begingroup\$ @manatwork It seems I did, yeah :p \$\endgroup\$ Feb 27 at 22:29
2
\$\begingroup\$

Atari 600XL, 22 bytes

Sorry I overread that it's not allowed to use the characters 1-9.

I think it is really stupid to say my language can this is a shorter way, because every language today contains more than a bunch of foreign frameworks. IMHO this "bytes" should be added to the real bytes you need to print values from 0 to 100 on the screen. Therefore a good old Atari 600XL with 16kib of RAM only need: 22 bytes. No other Software is need everything is build in.

Switch the hardware on, wait 2-3sec and type: f.a=0toasc("d"):?a:n.a

'f.' is an allowed shortcut for 'for' and 'n.' is a shortcut for 'next'

Maybe the C64 need also such less bytes.

Everything else need megabytes of extra hidden bytes.

JM2C

\$\endgroup\$
1
  • \$\begingroup\$ Interesting point. It's easy to make a ridiculously complex instruction set language where every unicode character maps to a function, so something like C triggers a routine to output 0-100, and have a 1 byte program hiding behind a vast software library. In fairness though, even the BASIC example does rely on the interpreter built into ROM, so it IS accessing something else, as is everything except machine code. Of course, back in the 8-bit days code-golf wasn't a game - it was standard practise - you had to be clever with the memory. No importing standard libraries using hundreds of MB! \$\endgroup\$ Mar 2 at 4:05
2
\$\begingroup\$

BASIC, 32 27 bytes

for a=0 to asc("d"):?a:next

Try it online!

while(a<asc("e")):?a:a=a+!0:wend

Of course, a FOR loop is shorter than using WHILE. Thanks Lars for your example.

My earlier (apparently invalid) attempt, which got downvoted for not stopping at 100:

0 ?a:a=a+!0:goto 0

Try it online!

I'll leave it here for completeness - only 18 bytes though.

Now this is not going to beat some volcano in New Zealand either... that said, it would work on 8-bit computers where the entire language interpreter was on a ROM that might be 2-16 KILObytes for the whole thing. Every bytes counted (like code golf) - there certainly wasn't space to add topographical data for the developer's favourite mountain range. 😂

\$\endgroup\$
2
2
\$\begingroup\$

Forth, 30 bytes

char e false [do] [i] . [loop]

Try it online!

commented:

char e \ ascii value 101
false \ 0
[do] \ loop a fixed number of times
[i] \ retrieve the iterator value
. \ print the top of the stack as a number, followed by a space
[loop] \ end of loop
\$\endgroup\$
3
  • \$\begingroup\$ You can use 'e instead of char e, and 0 is allowed in the challenge. \$\endgroup\$
    – Bubbler
    Mar 7 at 23:48
  • \$\begingroup\$ @Bubbler 'e isn't standard. I already made another post that uses zero. \$\endgroup\$
    – binarycat
    Mar 7 at 23:58
  • 1
    \$\begingroup\$ Our current site culture is that a language's standard doesn't matter much in code golf. It just matters whether the code works in at least one existing implementation of the language (in this case it works in gforth, at least). For example, tips for golfing in C has tons of compiler-specific hacks. But it's fine to stick with the standards, as long as you mention in the post that you're restricting yourself to standard features (otherwise you'll likely get similar comments). \$\endgroup\$
    – Bubbler
    Mar 8 at 0:09
2
\$\begingroup\$

Forth, 26 bytes

char e 0 [do] [i] . [loop]

Try it online!

commented:

char e \ ascii value 101
0
[do] \ loop a fixed number of times
[i] \ retrieve the iterator value
. \ print the top of the stack as a number, followed by a space
[loop] \ end of loop
\$\endgroup\$
2
  • \$\begingroup\$ For golfing improvements of your own post, please don't post a separate answer. You can edit your existing post instead. \$\endgroup\$
    – Bubbler
    Mar 8 at 0:00
  • \$\begingroup\$ I didn't really mean to, I just hit post and apperently I already did somehow? \$\endgroup\$
    – binarycat
    Mar 8 at 0:36
2
\$\begingroup\$

CSASM v2.2.1.2, 143 bytes

func main:
.local a : obj
push 0
pop a
inc a
inc a
push a
inc a
inc a
inc a
push a
mul
dup
mul
pop a
lda 0
.lbl a
inc $a
push $a
dup
print.n
push a
sub
brtrue a
ret
end

Commented and ungolfed:

func main:
    .local onehundred : obj

    ; Calculate 100
    push 0
    pop onehundred
    inc onehundred
    inc onehundred
    push onehundred
    ; Stack: [ 2 ]
    inc onehundred
    inc onehundred
    inc onehundred
    push onehundred
    ; Stack: [ 2, 5 ]
    mul
    ; Stack: [ 10 ]
    dup
    ; Stack: [ 10, 10 ]
    mul
    ; Stack: [ 100 ]
    pop onehundred

    lda 0
    .lbl loop
        ; Print $a
        inc $a
        push $a
        dup
        print.n

        ; Zero is falsy.  Check if $a - 100 == 0
        push onehundred
        sub
        brtrue loop
    ret
end
\$\endgroup\$
2
\$\begingroup\$

Kotlin, 42 bytes

It ain't much but it's honest work

fun main(){for(i in 0..0xa*0xa)println(i)}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Excel, 23 22 23 bytes

=SEQUENCE(CODE("e"),,0)

Spreadsheet

Invalid Change

=SEQUENCE(CODE("e"))-1
\$\endgroup\$
3
  • 1
    \$\begingroup\$ There's a forbidden 1 in your code. The original one is fine. \$\endgroup\$
    – Dorian
    Jul 8 at 9:50
  • 2
    \$\begingroup\$ @Dorian, This is a fine example of me thinking I'm clever when I am being stupid. Thanks for keeping me honest. \$\endgroup\$
    – Axuary
    Jul 8 at 15:32
  • \$\begingroup\$ How about =SEQUENCE(ROW(),,0) in A101? \$\endgroup\$ Oct 25 at 18:57
2
\$\begingroup\$

Vim, 16 bytes

i0<Esc><C-a>s<C-r>=r    <C-r>"0<C-r>")

Try it online!

Explanation:

i0<Esc>                                 # Insert `0`
       <C-a>                            # Increment
            s                           # Delete into register " and Insert
             <C-r>=                     # Start expression
                   r                    # Tab-autocomplete `range(`
                        <C-r>"          # 1
                              0         # 0
                               <C-r>"   # 1
                                     )  # Full expression is `range(101)`
                                        # Insert the range [0..101)

Alternatively (and more interesting, imo):

Vim, 18 bytes

iYp<C-v><C-a>0<Esc>d^@=!0
00@-

Try it online!

Explanation:

iYp<C-v><C-a>0<Esc>        # Insert `Yp<C-a>0`
                   d^      # Delete `Yp<C-a>`
  @-                       # Execute `Yp<C-a>`... times
                     @=!0  #                  1
00                         #                   00
\$\endgroup\$
2
\$\begingroup\$

Java 106 bytes

class p {public static void main(String[] args){int i='A'/'A';while(i<=(int)'d')System.out.println(i++);}}}}

TIO

\$\endgroup\$
4
  • \$\begingroup\$ can't say about size but yeah logic sorta be cool. :) \$\endgroup\$
    – Ha'Penny
    Oct 22 at 13:12
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! Don't worry about the size, as long as there's an attempt to golf it as much as you can, pretty much any serious answer is accepted here. :) After all, we allow answers in Unary, which typically has answers in the hundreds of thousands of bytes or more! \$\endgroup\$ Oct 22 at 13:25
  • \$\begingroup\$ You can check out the tips for golfing in Java if you want, but this looks pretty good! I edited it a tiny bit to use code block formatting. \$\endgroup\$ Oct 22 at 13:29
  • \$\begingroup\$ 94 bytes \$\endgroup\$
    – ceilingcat
    Oct 24 at 6:49
2
\$\begingroup\$

Oracle SQL, 56 bytes

select level-cos(0)from dual connect by level<ascii('f')

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (V8), 30 bytes

for(i=0;+!print(i)+'00'-i++;);

Try it online!

Jo king saves more bytes that I can count :)

\$\endgroup\$
0
2
\$\begingroup\$

!@#$%^&*()_+, 13 bytes

e($!#^$_^_
@)

Try it online!

Explaination:

e($!#^$_^_
@)

e            Pushes 101 onto the stack
 (           While
  $          Swap
   !#        Output number without popping and newline
     ^       Top of stack = Top of stack + 1
      $      Swap
       _^_   Top of stack = Top of stack - 1
<newline>    Push 10
@            Output top of stack as ASCII and pop
 )           Close while
\$\endgroup\$
2
\$\begingroup\$

Labyrinth, 18 bytes

0) @
0 \(
)#":
 (!

Try it online!

Push 101 () is increment and 0 is "append zero" command), and run "print stack height - 1, dup, decrement" until the top becomes zero.

Labyrinth, 19 bytes

0)
0
)}:!
 " \
@({)

Try it online!

Keep track of two values a=0 and b=101, print a and increment and decrement b until b becomes zero.

\$\endgroup\$
2
  • \$\begingroup\$ 17 bytes and alternative. There's probably another byte to be saved? \$\endgroup\$
    – Jo King
    Oct 29 at 9:44
  • \$\begingroup\$ Ah, 16 bytes with termination by division by zero \$\endgroup\$
    – Jo King
    Oct 29 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy