34
\$\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\$
4
  • 9
    \$\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\$ – Redwolf Programs Feb 25 at 0:06
  • 5
    \$\begingroup\$ Is there a requirement to stop printing at 100? \$\endgroup\$ – spuck Feb 25 at 16:44

101 Answers 101

4
\$\begingroup\$

MY BASIC, 29 bytes; BBC BASIC 27 bytes

for i=0 to 0xa*0xa
print i
next

Try it online!

Edit: Thanks for upvoting! I have found there is a BASIC dialect with even shorter syntax for hexadecimals (it's in BBC BASIC):

for i=0 to &a*&a
print i
next

that's minus 2 bytes :)

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Welcome to the site, and nice first answer! \$\endgroup\$ – caird coinheringaahing Feb 26 at 15:48
  • \$\begingroup\$ Doesn't BBC BASIC also have keyword abbreviations e.g. p.i for print i? \$\endgroup\$ – Neil Mar 8 at 0:36
  • \$\begingroup\$ that would normally be done with a question mark: ? i - but not in BBC BASIC \$\endgroup\$ – Werner Stauffacher Mar 8 at 19:58
4
\$\begingroup\$

Bash, 26 bytes

eval echo {$[x++]..${x}00}

Try it online!

(Previously)

Bash, 28 bytes

eval echo {$((++x))..${x}00}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! Nice first answer. \$\endgroup\$ – Redwolf Programs Feb 27 at 0:05
  • 1
    \$\begingroup\$ Your solution doesn't output 0, but fortunately the fix will cost you no extra character: just change the pre-increment to post-increment. While fixing it, you could change the $((..)) arithmetic evaluation to the deprecated but still functional old $[..] syntax to save 2 characters. (We have Tips for golfing in Bash in case you are looking for more tips.) \$\endgroup\$ – manatwork Feb 27 at 0:12
  • \$\begingroup\$ Thx for the tips @manatwork. Updated \$\endgroup\$ – Joshua Huber Mar 2 at 3:05
4
\$\begingroup\$

dc, 13 characters

Thanks to

  • Daemon for reusing stack depth instead of getting it again, to use shorter operator (-1 character)
[zpdA0>x]dsxx

Try it online!

dc, 14 characters

Thanks to

  • Digital Trauma for the twist in using the stack depth efficiently (-2 characters)
[zpzA0!<m]dsmx

Try it online!

dc, 16 characters

0[pz+dA0>i]dsixp

Sample run:

bash-5.0$ dc -e '0[pz+dA0>i]dsixp' | head
0
1
2
3
4
5
6
7
8
9

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Similar idea, same score \$\endgroup\$ – Digital Trauma Feb 23 at 20:41
  • 1
    \$\begingroup\$ Thanks @DigitalTrauma. I tried that too earlier, but only now, seeing your suggestion I found the more efficient way. \$\endgroup\$ – manatwork Feb 23 at 20:54
4
\$\begingroup\$

, 96 93 bytes

^+++(###....+###....+++<..#+...-....###+.@#+...$)+).>+++.$#+...^##=.+###.-#+....+)<++(-+##++>

Unwrapped:

        ^ + + +
        ( # # #
        . . . .
        + # # #
. . . . + + + < . . # + . . . -
. . . . # # # + . @ # + . . . $
) + ) . > + + + . $ # + . . . ^
# # = . + # # # . - # + . . . .
        + ) < +
        + ( - +
        # # + +
        > . . .

I'm not able to provide a direct link, but here you should be able to fork the project and replace the script.txt with either of the above scripts.

\$\endgroup\$
1
  • \$\begingroup\$ NO idea what this is doing but it looks so pretty 😍 +1 \$\endgroup\$ – roblogic Mar 6 at 4:14
3
\$\begingroup\$

Powershell, 18 bytes

0..[byte][char]'d'
\$\endgroup\$
4
  • 1
    \$\begingroup\$ -5 bytes Try it online! \$\endgroup\$ – Zaelin Goodman Feb 23 at 18:12
  • 1
    \$\begingroup\$ -9 bytes Try it online! \$\endgroup\$ – Julian Feb 23 at 21:25
  • \$\begingroup\$ @ZaelinGoodman, Julian for some unknown reason I can't access TIO, I will update as soon as I can go, thanks! \$\endgroup\$ – Wasif Feb 24 at 6:56
  • \$\begingroup\$ @Julian Wow, nice one!! \$\endgroup\$ – Zaelin Goodman Feb 24 at 13:00
3
\$\begingroup\$

Zsh, 12 bytes

seq 0 $[##d]

Try it online!

  • seq: count
    • from 0
    • $[##d]: to the character value of d
\$\endgroup\$
3
\$\begingroup\$

APL(Dyalog Unicode), 8 bytes SBCS

⍳⎕UCS'e'

Try it on APLgolf!

A tradfn submission which prints with space separator.

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

Husk, 4 bytes

ŀc'e

Try it online!

Surprised Husk doesn't have a builtin for 100.

How it works

ŀc'e - Main function, no arguments
  'e - Character literal "e"
 c   - Convert to charcode; 101
ŀ    - Lowered range; [0, 1, ..., 100]
\$\endgroup\$
3
\$\begingroup\$

MATL, 6 5 6 bytes

O'd'&:

Try it out at MATL Online

Explanation

O     % Letter O which is a pre-defined literal for zero
'd'   % String literal, 'd' (ASCII 100)
&:    % Create an array from 0...100
      % Implicitly print the result
\$\endgroup\$
2
  • \$\begingroup\$ I think it's supposed to range from 0 to 100 -- I made the same mistake myself. \$\endgroup\$ – Giuseppe Feb 24 at 12:16
  • \$\begingroup\$ @Giuseppe Good call, I saw the 1,2,3,4,5,... in the description and got confused! \$\endgroup\$ – Suever Feb 24 at 14:31
3
\$\begingroup\$

Befunge-98 (FBBI), 13 11 bytes

.0!+::'e%j@

-1 byte thanks to @ovs

-1 byte thanks to @PizgenalFilegav

Try it online!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 'd is a byte shorter than aa*. \$\endgroup\$ – ovs Feb 23 at 18:25
  • \$\begingroup\$ Also, using %j@ is a byte shorter than the conditional. \$\endgroup\$ – Pizgenal Filegav Feb 24 at 7:00
  • \$\begingroup\$ @ovs I forgot to look at Befunge's tips :) thanks! \$\endgroup\$ – Cinaski Feb 24 at 16:25
  • \$\begingroup\$ @PizgenalFilegav nice catch! But I don't quite get why the jump doesn't skip the first instructions, does it reset when wrapping around? \$\endgroup\$ – Cinaski Feb 24 at 16:27
  • \$\begingroup\$ @Cinaski I'm not completely sure either, but I think it's because Befunge-98's wrapping behavior works by backtracking until it actually reaches the opposite side of the program, and it only happens after the jump is complete. \$\endgroup\$ – Pizgenal Filegav Feb 24 at 17:34
3
\$\begingroup\$

K (ngn/k), 6 bytes

!0+"e"

Try it online!

Uses 0+ to convert "e" to an integer, then takes the range from 0 up to, but not including, that value (101).

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

Python 3, 96 bytes

import sys
n=0xb%0xa;m=0xa*0xa;p=lambda x:m if x>m else sys.stdout.write(str(x)+",")&p(x+n);p(n)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ I don't think int(...) is needed around 0xa or 0xb etc. Also, you need to include the score in the post header (the number of bytes in case of code-golf). \$\endgroup\$ – Bubbler Feb 25 at 7:14
  • \$\begingroup\$ 65 bytes Prints newline instead of ,, and doesn't have the trailing ,. Also, your solution didn't start from 0, it started from 1. This fixes that \$\endgroup\$ – Samathingamajig Feb 26 at 0:11
3
\$\begingroup\$

Whitespace, 58 bytes

Another in the theme of "this language doesn't even care about digit characters".

   

  
 
 	
 	   	 	 
	
     	
	    
    		  	 	
	  	
		

Try it online!

The program with comments:

[Push  0 
][Label
  
][Dup 
 ][PrintNum	
 	][Push  10 	 	 
][PrintChar	
  ][Push  1 	
][Add	   ][Dup 
 ][Push  101 		  	 	
][Subtract	  	][JmpNeg
		
]

Try it online!

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

Japt, 2 bytes

òL

Try it online!

Calls the function ò on the variable U with the variable L as an argument. U is 0 when the program has no input, L is 100 whenever a program starts, and the function ò returns the inclusive range from "this" (U) to its first argument (L).

Also valid:

Calls the function ò on the variable L with no arguments. With no arguments ò returns the inclusive range from 0 to "this". This one ignores input, rather than requiring no input.

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

Arn -h, 2 bytes

PS. You need to hand-type that flag because the permalink for flags is not working.

0|

Try it

Explained

0   # 0
 |  # concatenated with
    # (implicit) the range [1 .. 100]

Implicit output
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Im very late, but thanks for pointing out that bug. I'll fix it now \$\endgroup\$ – ZippyMagician Apr 11 at 2:27
3
\$\begingroup\$

Vim, 20 bytes

i0<esc><C-A>s<C-R>=range(<C-R>"0<C-R>")

Try it online!

Trying to improve on Razetime's answer, I stumbled upon the range function, which works wonders for this task. i<C-R>=range(101)\n would print the numbers we want, we just need to be a little creative to do it without 1.

Explanation

i0<esc><C-A>s<C-R>=range(<C-R>"0<C-R>")
i0<esc>                                    Insert a single 0
       <C-A>                               Increase it to a 1
            s                              Cut the 1 and go back to insert mode
             <C-R>=                        Write the result of the following function
                   range(             )    A range of numbers from 0 to N-1
                         <C-R>"            The last text that was deleted (1)
                               0           0
                                <C-R>"     1 again
\$\endgroup\$
1
  • \$\begingroup\$ -4 bytes by using tab autocomplete on the range() function. Also, it doesn't work on TIO, but if you start Vim with the +startinsert flag, you don't need the i at the beginning and save another -1 bytes: vim +startinsert testfile \$\endgroup\$ – Aaron Miller Apr 26 at 14:03
2
\$\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\$ – EliteDaMyth Feb 23 at 15:58
  • \$\begingroup\$ @EliteDaMyth thanks for that! \$\endgroup\$ – Wasif Feb 23 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\$ – EliteDaMyth Feb 23 at 16:02
  • \$\begingroup\$ @EliteDaMyth thanks again! \$\endgroup\$ – Wasif Feb 23 at 16:04
  • 3
    \$\begingroup\$ you don't need the + in front of atob`MTAx`; \$\endgroup\$ – Wzl Feb 23 at 17:15
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
  • 1
    \$\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\$ – eternaldebugging 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\$

Bash, 15 bytes

seq `dc<<<A0Kf`

Try it online!

  • 1 byte saved, thanks to @manatwork.

Previous answer:

Bash + GNU utils, 20

seq 0 inf|sed /.../q

Count from zero to infinity, but stop after the first 3-digit number.

Try it online!


Pure Bash - no external utilities, 32 bytes

a=(a {a..j}{a..j})
echo ${!a[@]}

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Your newest solution skips “0” because you missed a space between seq's parameters. Sorry, that looks like +1 character. ☹ \$\endgroup\$ – manatwork Feb 23 at 20:28
  • \$\begingroup\$ @manatwork oops - yes, thanks - fixed. \$\endgroup\$ – Digital Trauma Feb 23 at 20:30
  • 1
    \$\begingroup\$ As apology, here is a 15 character one, still based on your idea: seq `dc<<<A0Kf`. \$\endgroup\$ – manatwork Feb 23 at 20:31
  • \$\begingroup\$ @manatwork - thanks! \$\endgroup\$ – Digital Trauma Feb 23 at 20:43
  • 1
    \$\begingroup\$ @Downvoter - please explain how I may improve this answer. \$\endgroup\$ – Digital Trauma Feb 23 at 20:56
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\$ – Michael Stern 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\$ – Michael Dorgan Feb 25 at 19:18
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\$ – Olivier Grégoire 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\$ – Olivier Grégoire 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\$ – Olivier Grégoire 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\$ – Olivier Grégoire 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\$ – Redwolf Programs 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\$ – Redwolf Programs Feb 27 at 22:29
2
\$\begingroup\$

Wolfram Language (Mathematica), 20 bytes

The only real golfing opportunity for this question in the Wolfram language is to encode the number 100 with as few bytes as possible. There is only one real-valued constant symbol in the Wolfram language with a one byte name, namely E.

I thus looked for combinations of binary operations that were near 100. (E+E)^E is about 99.73, so adding E/E will give a suitable endpoint.

Range[0,(E+E)^E+E/E]

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ You can change E/E to 0! to save a byte. \$\endgroup\$ – Axuary Mar 2 at 4:16
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\$

PHP, 26 bytes

print_r(range(0,0xA*0xA));

Try it online!

\$\endgroup\$

Your Answer

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