66
\$\begingroup\$

Print integers 0 to 100 (inclusive) without using characters 123456789 in your code.

Separator of numbers can be comma or white space (by default <blank>, <horizontal tabulator>, <newline>, <carriage return>, <form feed> or <vertical tabulator>).

Shortest code wins.

\$\endgroup\$
7
  • 15
    \$\begingroup\$ Many tricks are made possible by allowing 0. Which is what makes this challenge interesting, IMO. \$\endgroup\$
    – Arnauld
    Feb 23, 2021 at 17:08
  • 3
    \$\begingroup\$ I thought "do X without Y" questions weren't allowed anymore. \$\endgroup\$
    – Purple P
    Feb 24, 2021 at 3:34
  • 5
    \$\begingroup\$ @PurpleP They're allowed, but discouraged. Interesting ones are fine. \$\endgroup\$ Feb 25, 2021 at 0:06
  • 16
    \$\begingroup\$ Is there a requirement to stop printing at 100? \$\endgroup\$
    – spuck
    Feb 25, 2021 at 16:44
  • 2
    \$\begingroup\$ Can I use non-ASCII encoding? \$\endgroup\$
    – user100411
    Oct 17, 2021 at 20:36

170 Answers 170

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, 2021 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, 2021 at 17:44
  • \$\begingroup\$ Ah that's how java answers are considered? thanks \$\endgroup\$
    – Cray
    Feb 26, 2021 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, 2021 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, 2021 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, 2021 at 21:49
  • \$\begingroup\$ @RedwolfPrograms, so you missed EliteDaMyth's solution? \$\endgroup\$
    – manatwork
    Feb 27, 2021 at 22:17
  • \$\begingroup\$ @manatwork It seems I did, yeah :p \$\endgroup\$ Feb 27, 2021 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, 2021 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, 2021 at 23:48
  • \$\begingroup\$ @Bubbler 'e isn't standard. I already made another post that uses zero. \$\endgroup\$
    – binarycat
    Mar 7, 2021 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, 2021 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, 2021 at 0:00
  • \$\begingroup\$ I didn't really mean to, I just hit post and apperently I already did somehow? \$\endgroup\$
    – binarycat
    Mar 8, 2021 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\$

Pyth, 4 bytes

UC\e

Try it online!
Surprised myself by topping the previous Pyth's top score of 5 bytes. Creates a range from 0-101 (char code of 'e' = 101)

\$\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, 2021 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, 2021 at 15:32
  • \$\begingroup\$ How about =SEQUENCE(ROW(),,0) in A101? \$\endgroup\$ Oct 25, 2021 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, 2021 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, 2021 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, 2021 at 13:29
  • 1
    \$\begingroup\$ 94 bytes \$\endgroup\$
    – ceilingcat
    Oct 24, 2021 at 6:49
2
\$\begingroup\$

Oracle SQL, 56 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ instead of -cos(0), I would imagine you could write +~0 \$\endgroup\$ May 12, 2022 at 10:34
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\$ 11 \$\endgroup\$ Apr 17, 2022 at 4:32
  • \$\begingroup\$ (Of course, replacing _^_ with * is 11 as well) \$\endgroup\$ Apr 17, 2022 at 4:34
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, 2021 at 9:44
  • \$\begingroup\$ Ah, 16 bytes with termination by division by zero \$\endgroup\$
    – Jo King
    Oct 29, 2021 at 9:59
2
\$\begingroup\$

Pure Bash, 34 + 1 = 35 bytes

Filename must be x; this is for extra one byte.

echo $[x++]
a=x
((x>${#a}00))||. x

Try it online!

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

Lua (29 bytes)

for i=0,0xA..0 do print(i)end
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Apr 16, 2022 at 3:18
2
\$\begingroup\$

HBL, 2 bytes

00'%

Try it here!

Explanation

0     Inclusive range
 0    from 0
  '%  to 100
\$\endgroup\$
2
\$\begingroup\$

Julia, 19 bytes

;echo $(0:Int('d'))

This only works in the REPL as the ; it used to enter the shell mode.

In a normal Julia file, this

println.(0:Int('d'))

works and is 20 bytes long.

If we allow the values to be printed as part of an error message, this

;$(0:Int('d'))

does it in 14.

If the printing isn't required (as Julia shows the value of the last line in the terminal) then, [0:Int('d')...] only has 15 bytes.

edit: reverted to my first solution as the improved one had a '2' in it. Oups

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Welcome to Code Golf! Great answer and explanation. \$\endgroup\$
    – Seggan
    Jul 11, 2022 at 18:09
  • \$\begingroup\$ That is very true. I removed my edit. \$\endgroup\$ Jul 12, 2022 at 15:17
2
\$\begingroup\$

><>, 11 bytes

lnaol:aa*(%

Try it online!

Terminates by error.

\$\endgroup\$
1
  • \$\begingroup\$ Note that this is still the shortest way to do this, even without the source restriction \$\endgroup\$
    – Jo King
    Feb 8 at 22:34
2
\$\begingroup\$

Rust, 49 bytes

(0..'e' as usize).for_each(|x| print!("{} ",x));

  • 'e' as usize casts literal 'e' to its Unicode number
  • Creates a Range and then for each of the elements in the range, prints the elements.
\$\endgroup\$
1
  • \$\begingroup\$ Oops, totally did not see that! @WheatWizard. Changed u32 to usize. \$\endgroup\$
    – StaticESC
    Feb 13 at 4:36
2
\$\begingroup\$

Itr, 10 bytes

'eMºM»£'
¥

online interpreter

4 bytes ('eMº) if surrounding the output with brackets is allowed

Explanation

'e          ; the literal 'e' (ascii 101)
  Mº        ; unwrap string,and convert to 0-based range
    M»      ; for every element of the range
      £     ; print the element
       ' 
        ¥   ; print a newline
\$\endgroup\$
2
\$\begingroup\$

Ly, 9 5 3 bytes

'dR

Try it online!

Dropped 4 chars thanks for LyricLy(!)

Prints using LF as the delimiter by generating the list of 0-100 on the stack, then using a "print the whole stack" command.

 'd   - push 100 (codepoint for "d") on the stack
   R  - use "range" command to generate the list of numbers
      - the stack prints as numbers automatically
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 'dR&u is 5 bytes using implicit 0 and the Range command. \$\endgroup\$
    – LyricLy
    Nov 8, 2021 at 7:49
2
\$\begingroup\$

Backhand, 13 bytes

:_@v^O-
e]'}:

Try it online!

I don't feel like this is optimal, but I can't figure out how to do better than that.

The literal newline is just a command that prints a newline, so I replaced it with n so that the explanation is hopefully easier to follow.

The entire program is a single loop that mostly operates with step size 2 (to minimize unused spaces).

:_@v^O-ne]'}:   initial step size is 3
                stack contains the current loop counter `n`, or empty (implicit 0)
:               [n n] duplicate
   v            reduce step size to 2
     O          [n] output as number
       n        output literal newline
         ]      [n+1] increment
           }    bump the IP once to the right, so it can run
                different instructions on the way back
            :   [n+1 n+1] duplicate
        e '     [n+1 n+1 101] push 'e' = 101
      -         [n+1 n-100] subtract
    ^           increase step size to 3
 _              if the top is 0, bump to the right, otherwise bump to the left
  @             right: halt
                left: return to the beginning of the loop
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 12 bytes: ]Eb:d*O'j\n:@ \$\endgroup\$
    – Jo King
    Sep 20 at 10:26
2
\$\begingroup\$

Nibbles, 1.5 bytes (3 nibbles)

:`,

Attempt This Online!

:`,     # full program
:`,$$   # with implicit args shown;
:       # join
 `,     #   range from 0 to value minus 1:
   $    #     value = 100
        #     (if no input is given to a nibbles program,
        #     the variable '$' is assigned a value of 100)
    $   #   to 100

Note that the program :`, is the human-readable form of the code (incidentally not containing the characters 1-9).
The actual 1.5-byte Nibbles program consists of the nibbles 0111, 1011 and 0111. By default, these are saved with a 'padding' nibble of 0110 to make-up a whole number of bytes in operating systems that cannot store fractional-byte files. This could be interpreted as a 2-character program {v: note that this does not contain the characters 1-9 either.

\$\endgroup\$
1
\$\begingroup\$

VBScript, 33 bytes

for i=0 to asc("d")
msgbox i
Next

Competitive answer in VBScript!

\$\endgroup\$
1
  • \$\begingroup\$ I noticed your answer is similar to my answer \$\endgroup\$
    – Eric Xue
    Jul 10, 2022 at 16:01
1
\$\begingroup\$

Javascript (Browser), 53 46 37 33 bytes

for(n=0;++n<+atob`MTAx`;)alert(n)

-15 bytes thanks to @EliteDaMyth

\$\endgroup\$
7
  • 1
    \$\begingroup\$ change the parseInt() to +atob`MTAx` for 11 bytes \$\endgroup\$
    – user100752
    Feb 23, 2021 at 15:58
  • \$\begingroup\$ @EliteDaMyth thanks for that! \$\endgroup\$
    – Wasif
    Feb 23, 2021 at 16:00
  • 1
    \$\begingroup\$ also @Wasif you dont need the curly braces after the for loop. and you can change the way the for loop works, by incrementing, while checking, i.e. for(n=0;++n<+atob`MTAx`;)alert(n) this is 33 bytes \$\endgroup\$
    – user100752
    Feb 23, 2021 at 16:02
  • \$\begingroup\$ @EliteDaMyth thanks again! \$\endgroup\$
    – Wasif
    Feb 23, 2021 at 16:04
  • 4
    \$\begingroup\$ you don't need the + in front of atob`MTAx`; \$\endgroup\$
    – Wezl
    Feb 23, 2021 at 17:15
1
\$\begingroup\$

J, 12 bytes

a.i.@i.'e'"_

Try it online!

\$\endgroup\$
7
  • \$\begingroup\$ i.a.i.'e' for 9 works fine for me... \$\endgroup\$ Feb 27, 2021 at 20:58
  • \$\begingroup\$ i.'e' returns 101, \$\endgroup\$ Feb 27, 2021 at 21:05
  • \$\begingroup\$ Sadly that’s a snippet hence not legal according to site rules \$\endgroup\$
    – Jonah
    Feb 27, 2021 at 21:51
  • \$\begingroup\$ For more, see this meta discussion \$\endgroup\$
    – Jonah
    Feb 27, 2021 at 22:05
  • \$\begingroup\$ Hi Jonah could you please specify the difference between a snippet and a function, particularly in regard to J \$\endgroup\$ Mar 28, 2022 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.