61
\$\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\$
7
  • 14
    \$\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
  • 3
    \$\begingroup\$ @PurpleP They're allowed, but discouraged. Interesting ones are fine. \$\endgroup\$ Feb 25, 2021 at 0:06
  • 12
    \$\begingroup\$ Is there a requirement to stop printing at 100? \$\endgroup\$
    – spuck
    Feb 25, 2021 at 16:44
  • 1
    \$\begingroup\$ Can I use non-ASCII encoding? \$\endgroup\$
    – user100411
    Oct 17, 2021 at 20:36

147 Answers 147

1 2 3 4
5
1
\$\begingroup\$

C++, 77 Bytes

#import<iostream>
main(){for(int i=0;i<=int('d');++i)  std::cout<<i<<" ";}

Here, I've used the ASCII value and ran the loop and printed the value. Simple!

\$\endgroup\$
1
  • \$\begingroup\$ This can definitely be golfed a bit, like by removing unnecessary whitespace and newlines. Make sure to read our tips questions if you want some hints! \$\endgroup\$ Mar 8, 2021 at 18:14
1
\$\begingroup\$

TeX, 57 bytes

\newcount~\loop\advance~`^^A\the~ \ifnum~<`^^%\repeat\bye

Makes uses of these two tricks:

  • \$\rm\TeX\$'s preprocessor runs through the code and replaces any instance of two consecutive superscript (category code 7) characters followed by a character token, and adds/subtracts 64 from its ascii code, hence ^^A becomes NUL.
  • \$\rm\TeX\$ has a `backtick notation' of inputting numbers that reads the following character's ascii code instead.
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 8/11 bytes

'e'{}/,`

Try it online! - 8 Bytes

Makes an array of values of e (101) elements, starting at 0, then formats with spaces. The format also has brackets at either end of the output, so it may not be valid. If not, they can be removed with 3 more bytes:

'e'{}/,' '*

Try it online! - 11 Bytes

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

V (vim), 30 bytes

i00<esc><C-a>hxpi0<esc>0"aDi0<esc>qqYp<C-a>q@a@qdd

Try it online!

can definitely be improved.

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

K (oK), 4 bytes

Solution:

!"e"

Try it online!

Explanation:

Scrolling through the other solutions tells me I wasn't as novel as I hoped when I came up with this.

!"e" / the solution
 "e" / ASCII 101
!    / til (i.e. range 0..n-1
\$\endgroup\$
1
\$\begingroup\$

Barrel, 9 bytes

#d(n+¶)n

Explanation:

#        // as many times as...
 d       // ...the ASCII value of 'd' (100)...
  (   )  // Create a single of instruction for the loop
   n     // print the accumulator of a number
    +    // increase the accumulator
     ¶   // print a newline
       n // print the final number

The final n is necessary because the loop only prints the numbers 0 to 99.

I could've shaved off 2 bytes by doing #e(n+¶, which would have used the ASCII value of 'e' (101) and also utilized the self-closing properties of the () instruction, but I had already assigned e to be the value of the mathematical constant \$e\$.

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

Pxem, 21 20 bytes (filename) + 0 bytes (content) = 23 21 20 bytes, requires unprintable character.

  • Filename (escaped unprintable): \001.r.-.z.c.n,.o\001.+.ce.a
  • Content: empty.

Try it online!

With comments

XX.z
# push 1; push int(rand()*pop)
## NOTE rand() outputs 0<=n<1
## NOTE assuming NUL cannot be used for filename
.a\001.rXX.z
# while size<2 || pop!=pop; do
.a.zXX.z
  # dup; print pop; push comma; putc pop
  .a.c.n,.oXX.z
  # push 1; push pop+pop; dup; push 101
  .a\001.+.ce
# done
.a.a

Pxem, 3 bytes (filename) + 20 bytes (content) = 23 bytes, requires unprintable character.

  • Filename: e.e
  • Content (some unprintables are escaped): .c.w\001.-.e.+.n .o.d.a

With comment

e.eXX.z # push 101; call content
.a
XX.z
# dup; while pop!=0; do
.a.c.wXX.z
  # push 1; push abs(pop-pop); call content (* result of final stack will be pushed to original *)
  .a\001.-.eXX.z
  # push pop+pop; print pop; push space; print pop; return
  .a.+.n .o.dXX.z
# done; (* implicit return *)
.a.a

Try it online! (with pxem.posixism)

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

///, 231 166 bytes

/\\\\\/\//\\\/\/\/\/\/\/\/\/\/\/\/\///\/\\\/\/\//\\\/\
\/\\\\\\\/\
\\\/\/\\\\\\\/\\\/\\\/\\\\\\\\\\\/\/\/\\\/\\\/\\\\\\\\\\\/\/\\\\\\\/\
\\\/\/\/\\\/\///\\\\\\\\\\\//

Try it online!

This was really fun to make. Sadly, there is a single newline. Using a backslash instead breaks everything, and I don't really want to figure out where everything is and fix it.

Update: I remade it from the ground up, it is now much smaller, and works with only slashes. Unfortunately, the challenge specifies commas and whitespace seperators only, so only slashes is not allowed.

Slashes only:

///, 182 bytes

/\\\\\/\//\\\/\/\/\/\/\/\/\/\/\/\/\///\/\\\/\/\//\\\/\\\\\/\\\\\\\/\\\\\\\\\\\/\/\\\\\\\/\\\/\\\/\\\\\\\\\\\/\/\/\\\/\\\/\\\\\\\\\\\/\/\\\\\\\/\\\\\\\\\\\/\/\/\\\/\//\\/\\\\\\\\\\\//

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Looks like the output starts with 1, while should start with 0. \$\endgroup\$
    – manatwork
    Feb 28, 2021 at 17:39
  • \$\begingroup\$ @manatwork ill work on that ;) \$\endgroup\$ Mar 1, 2021 at 15:26
1
\$\begingroup\$

GFortran, 29 bytes

try it online!

print*,(j,j=0,ichar('d'))
end

Similar to this.

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

MathGolf, 4 bytes

♀)rn

Outputs with newline delimiter.

Try it online.

Explanation:

♀     # Push 100
 )    # Increment it to 101
  r   # Pop and push a list in the range [0,101)
   n  # Pop and join it by newlines
      # (after which the entire stack is output implicitly)
\$\endgroup\$
1
\$\begingroup\$

Python 3; 46 Bytes

x=True;a=x+x;b=a*a+x;print(*range(a*a*b*b+x))
\$\endgroup\$
0
1
\$\begingroup\$

ErrLess, 23 25 17 bytes

Thanks to Jo King for saving 8 bytes

0Z@#@'d<l+[.a?l-z

Explanation

0   { Add zero to the stack: (x) }
Z   { Set a "checkpoint" to jump back to later }
@#@ { Output as number & Duplicate: (x x) }
'd< { x < d - true -> -1; false -> 0? (x x<d) }
l   { Get the length of the top element (-1 for integers): (x x<d -1) }
+   { Add: (x [-2 or -1]) }
[   { Skip backwards that many instructions (skip forwards 1 or 2): (x) }
.   { Halt }
a?  { Push 10 and print (print newline) }
l-  { Increment: (x--1) }
z   { Go to "checkpoint" }

Try it online!

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

Ly, 9 5 bytes

'dR&u

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
    &u  - print the stack as integers
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 'dR&u is 5 bytes using implicit 0 and the Range command. \$\endgroup\$
    – LyricLy
    Nov 8, 2021 at 7:49
1
\$\begingroup\$

Go, 63 bytes

package main
func main(){for i:=' ';i<'';i++{println(i-' ')}}

Attempt This Online!

Upper bound for the loop has value 133 NEXT LINE (NEL). Separator is newlines. Prints to STDERR.

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

Kotlin, 48 46 bytes

('P'..'´').joinToString(","){""+it.minus('P')}

Saving two bytes by using other chars from the ascii table that only takes one instead of two bytes.

Try it online!

48 bytes version

('\n'..'n').joinToString(","){""+it.minus('\n')}

Using the ascii table to get those numbers.

Try it online!


When brackets are allowed at the start and end then this is smaller:

29 bytes

('P'..'´').map{it.minus('P')}

Try it online!

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

><>, 18 bytes

0::naoaa*(?!;ba-+!

Try it online!

Explanation

0                   Initialize stack with 0
 ::                 Duplicate the top of the stack twice, once for printing and once for comparing
   n                Pop the top of the stack, and print as a number
    ao              Push 0xa to the stack, and pop it to print as a char
      aa*           Push 100 (10*10) onto the stack
         (          Pop the top two values of the stack, and compare if one is less than the other
          ?!;       If not, halt execution, else...
             ba-    Push 1 (11-10) onto the stack
                +   Add the top two values on the stack
                 !  Skip the next instruction
                    IP Moves back to the 0
\$\endgroup\$
1
\$\begingroup\$

Pyth, 7 bytes

0S^ThhZ

Try it online!

Yay! First answer using an actual golfing languages. Since I’m new to Pyth, I’m assuming this can be optimized further :)

Edit: I misread the problem :/ so +1 byte. And guess what? Somebody made a 4 byte answer in pyth.

Explanation:

0         Zero
 S        In this case it makes a list from 1 to a number
  ^       Exponent of…
   T      Ten to the…
    hh    Increase the following number by two (one for each h)
     Z    Zero (now two after being increased)
          So basically push 0 then make a list from 1 to ten squared.
\$\endgroup\$
1
\$\begingroup\$

><>, 11 bytes

lnaol:aa*(%

Try it online!

Terminates by error.

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

Knight, 37 36 29 21 bytes

-8 bytes thanks to @Razetime for reminding me about the ASCII function, which made my entire coercion thing useless

;O=a 0W>A'd'aO=a++0Ta

Try It Online!

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

Python 3, 33 bytes

for x in range(ord("e")):print(x)
\$\endgroup\$
0
\$\begingroup\$

Elixir, 26 bytes

for x<-0..?d,do: IO.puts x

Try it online!

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

Batch, 56 bytes

@set/ax=0xb-0xa
@for /l %%b in (0,%x%,%x%00)do @echo %%b

-61 bytes for @Neil

\$\endgroup\$
6
  • 1
    \$\begingroup\$ You can just use set/ax=0xb-0xa to set x etc. \$\endgroup\$
    – Neil
    Feb 23, 2021 at 17:01
  • \$\begingroup\$ @Neil edited thanks \$\endgroup\$
    – Wasif
    Feb 23, 2021 at 17:53
  • \$\begingroup\$ Actually you don't need y at all, just use %x%00 in its place. \$\endgroup\$
    – Neil
    Feb 23, 2021 at 17:54
  • \$\begingroup\$ Also, some general Batch golfing tips: you don't need the space in set/a or )do, and you can remove the @echo off and use @set, @for and @echo instead. \$\endgroup\$
    – Neil
    Feb 23, 2021 at 17:56
  • \$\begingroup\$ @Neil thanks! for that \$\endgroup\$
    – Wasif
    Feb 23, 2021 at 17:58
0
\$\begingroup\$

Red, 36 bytes

repeat n 0 +#"e"[print n +#"a"-#"b"]

Try it online!

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

C (gcc), 40 39 bytes

Saved a byte thanks to att!!!

f(i){for(i=0;i<'e';)printf("%d ",i++);}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ 39 bytes \$\endgroup\$
    – att
    Feb 23, 2021 at 18:31
  • \$\begingroup\$ @att Nice one - thanks! :D \$\endgroup\$
    – Noodle9
    Feb 23, 2021 at 18:50
0
\$\begingroup\$

C++ gcc, 36 bytes

Try it online!

main(){for(;_<'e';)cout<<_++<<'\n';}

Explanation : I globally initialized varible _ so its initial value is 0, now ascii value of e is 101 so I ran the loop till my variable _ is less than 'e', instead of incrementing it inside the for loop I used post increment while printing to save 1 byte

edit: I misread the question and thought 0 is also not allowed :)

\$\endgroup\$
4
  • \$\begingroup\$ Could you explain the code please? \$\endgroup\$
    – user7467
    Oct 14, 2021 at 16:41
  • 1
    \$\begingroup\$ @Anush I have added explanation, hope it helps. \$\endgroup\$
    – cheems
    Oct 14, 2021 at 16:51
  • \$\begingroup\$ Do you know what this would be in C? \$\endgroup\$
    – user7467
    Oct 14, 2021 at 20:46
  • \$\begingroup\$ You'll have to include the _ declaration with the code I'm afraid, since it won't work without it. I'm not familiar with C++ golfing, but I believe you'd have to include the rest of the boilerplate, since this is a full program \$\endgroup\$
    – Jo King
    Oct 16, 2021 at 8:59
0
\$\begingroup\$

APOL, 11 bytes

f(ô p(∈));ô

I would've used instead of f, but the rules state that you have to include 0 so the fastest route was to just print 0-99 and slap 100 at the end.

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

APL, 13 bytes

0,⍳⍎'00',⍨⍕*0

*0 ⍝ Exponential of zero = 1
⍕ ⍝ Convert to symbol '1'
'00',⍨ ⍝ Append two zeros
⍎ ⍝ Convert to number 100
⍳ ⍝ Make sequence from 1 to 100
0, ⍝ Append zero to the left

\$\endgroup\$
1 2 3 4
5

Your Answer

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