57
\$\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
  • 2
    \$\begingroup\$ I thought "do X without Y" questions weren't allowed anymore. \$\endgroup\$
    – Purple P
    Feb 24, 2021 at 3:34
  • 2
    \$\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
  • \$\begingroup\$ Can we do it in reverse order? \$\endgroup\$
    – Dion
    Oct 16, 2021 at 9:51

137 Answers 137

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\$

PHP, 26 bytes

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

Try it online!

\$\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\$ Apr 11, 2021 at 2:27
3
\$\begingroup\$

Haskell - 31 19 bytes

Edit: From 31 bytes to 19 bytes, thanks to @binarycat's suggestion of using fromEnum instead of ord, which requires the Data.Char package.

Are imports cheating?

l=[0..fromEnum 'd']

Try it online!

Explanation:

Convert 'd' into it's ASCII integer value using the fromEnum function, which gives 100 and generate a list from 0 to 100.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ why import, fromEnum will do just fine. \$\endgroup\$
    – binarycat
    Mar 7, 2021 at 23:49
  • \$\begingroup\$ Didn't know that was a thing! I'm new to Haskell--Thanks for your suggestion :) \$\endgroup\$ Mar 7, 2021 at 23:52
  • \$\begingroup\$ you should probably also print the list, instead of just assigning it to a variable. \$\endgroup\$
    – binarycat
    Mar 7, 2021 at 23:59
  • \$\begingroup\$ You can get rid of the 'l=' if you run it in GHCi, for a saving of 2 bytes. \$\endgroup\$
    – Penguino
    Aug 2, 2021 at 23:29
3
\$\begingroup\$

javascript 77 bytes

let i=0;while(true){console.log(i);if(i.toString().includes('00'))break;i++;}
\$\endgroup\$
2
  • 4
    \$\begingroup\$ For starters, convention says you should include a bytecount on your posts. A good website for this is tio.run which can automatically format posts for you. Also, you could easily remove a lot of the whitespace, eg: -6 bytes. Apart from the basics, heres a handy guide for golfing specifically in JS. Good luck \$\endgroup\$
    – Underslash
    Jul 8, 2021 at 2:48
  • \$\begingroup\$ Thank you ill do it in my next posts :) \$\endgroup\$
    – moum bou
    Jul 8, 2021 at 4:52
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\$

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, 2021 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, 2021 at 9:00
3
\$\begingroup\$

KonamiCode, 54 50 55 bytes

v(>)>(^)v(^^^>^^)S(^>>^)>(>)L(>)<<<v((>))>(^)<<>(>)B(>)

A version with an explanation:

[You actually do need to inititalize address 0, my mistake. Also, my original version did not print 0.]

v(>) [Inititalizes address 0]
>(^) [Sets address pointer to 1, this is where the space character wil be held]
v(^^^>^^) [Writes 32 (a space) to memory]
S(^>>^) [Sets the comparison buffer to 101]
>(>) [Back to address 0]
L(>) [Loop marker]
<<< [Output the counter at address 0 as a number]
v((>)) [Increase the counter by 1]
>(^) [Goes to the space]
<< [Output the space]
>(>) [Back to 0]
B(>) [Done!]
\$\endgroup\$
3
\$\begingroup\$

Risky, 3 2 bytes

0:--

Try it online!

range(100 - -1)
\$\endgroup\$
3
\$\begingroup\$

Desmos, 25 bytes

o=0
o->[0...eeeln(eeeee)]

Not sure if this is an acceptable form of output but it's still an interesting answer imo. Click the right arrow (->) to run.

Try It On Desmos!

This takes advantage of Desmos's implicit rounding with list ranges, which will always round both start and end numbers to the nearest integer. In this case, eeeln(eeeee) is mathematically equivalent to \$e^3\cdot5\approx100.42768\$ (\$e\approx2.71828\$ is Euler's number), which rounds down to 100.

If not acceptable, then here's an alternative version that might be more acceptable:

31 bytes

l=[0...eeeln(eeeee)]
(l,0)
${l}

Paste first two equations into Desmos, and label the list of points (l,0) as ${l}. Move the viewport to the right to view more numbers.

Try It On Desmos!

\$\endgroup\$
2
  • \$\begingroup\$ wouldn't it be valid to remove o=0? because then you just click add slider and the output is there. but idk, should prob ask on meta \$\endgroup\$
    – Steffan
    May 12 at 4:01
  • \$\begingroup\$ @Steffan I considered that, but I'm not so sure if that's valid. I'm gonna ask on TNB and see what they say. \$\endgroup\$
    – Aiden Chow
    May 12 at 4:25
3
\$\begingroup\$

Vyxal, 3 bytes

₁ɾ⁋

Try it Online!

enter image description here

I guess so.

\$\endgroup\$
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, 2021 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, 2021 at 18:27
  • \$\begingroup\$ thanks @hakr14! \$\endgroup\$ Feb 23, 2021 at 19:18
  • 1
    \$\begingroup\$ @hakr14 May I introduce you to pythtemp.herokuapp.com Interpreter that works WITH documentation \$\endgroup\$
    – Scott
    Feb 26, 2021 at 0:43
  • \$\begingroup\$ @Scott :O thank you so much... \$\endgroup\$
    – hakr14
    Feb 26, 2021 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\$

Wolfram Language (Mathematica), 29 bytes

included more for the amusing built-in than the byte count, though this would be something like 9 bytes in the hypothetical mthmca golfing language.

Range[0,FromRomanNumeral@"C"]

Try it online!

And similar, but longer

Range[0, Interpreter["SemanticNumber"]@"hundred"]
\$\endgroup\$
1
  • \$\begingroup\$ +1 for use of stupid built-ins \$\endgroup\$
    – des54321
    Mar 18 at 14:18
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, 2021 at 10:45
  • \$\begingroup\$ Would somebody smarter than me explain how this knows to stop counting? \$\endgroup\$ Feb 25, 2021 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, 2021 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, 2021 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, 2021 at 20:18
  • \$\begingroup\$ @manatwork: Yes it is shorter, thanks. \$\endgroup\$
    – sergiol
    Feb 25, 2021 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, 2021 at 21:17
  • \$\begingroup\$ Yep, that rearrangement works, @manatwork. Thanks! \$\endgroup\$
    – BradC
    Feb 25, 2021 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, 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\$

Your Answer

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