69
\$\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
  • 16
    \$\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

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

6510 Assembler for C64 (159 Bytes)

*=$c000
a=0^0
b=a+a
    ldx #0
    txa
    dex
    stx r+b
    stx w+b
    stx z+b
    stx p+b
    stx o+b
    stx y+b
    sec
    sbc 0
    tay
    iny
    sty r+a
    sty w+a
    sty z+a
    sty p+a
    sty o+a
    sty y+a
    lda 0
    lsr
    lsr
    tay
    dey
    sty s+a
    ldy 0
    iny
    sty q+a
    sty t+a
    sty o-a
    tya
    iny
    sty p-a
    clc
    adc s+a
    sta x+a
    lda s+a
    clc
    adc s+a
    adc s+a
    tay
    iny
    iny
    sty z-a 
    lda 0
    asl
    tay
    iny
    iny
    iny
    iny
    iny
    iny
    sty c+a   
    ldx #0
d   txa
q   ldy #0
    sec
s   sbc #0
    bcc t
    iny
    bne s
t   cpy #0
    beq u
    sta v+1
    tya
r   jsr 0
v   lda #0
u   clc
x   adc #0
w   jsr 0
    lda #0
z   jsr 0
    inx
c   cpx #0
    bne d
    lda #0
p   jsr 0
    lda #0
o   jsr 0
y   jmp 0

\$\endgroup\$
1
  • \$\begingroup\$ Very good entry. \$\endgroup\$ Nov 17, 2023 at 16:26
1
\$\begingroup\$

Vyxal SH, 7 bitsv2, 0.875 bytes

ʀ

Try it Online!

Another flag cocktail.

Bitstring

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

COMMODORE 64 = 34 Bytes

With Commodore BASIC keyword abbreviations:

0?B:B=B-(A=.):IFB<aS(" ")*πgO

Or without the keyword abbreviations:

0 PRINTB:B=B-(A=.):IFB<ASC(" ")*πGOTO
\$\endgroup\$
1
  • \$\begingroup\$ I tidied up this entry to show the symbolic listings a bit better, and linked to the C64 Wiki for an explanation of Commodore BASIC Keyword Abbreviations. \$\endgroup\$ Nov 17, 2023 at 16:25
1
\$\begingroup\$

Hexagony, 19 bytes

&!)')$0<.0.>.;/-{@_

Try it online! or on hexagony.net

In hexagon layout:

   & ! )
  ' ) $ 0
 < . 0 . >
  . ; / -
   { @ _

Completely ungolfed:

    & ! ) {
   . . . . .
  . . . . . .
 & ) 0 ; 0 ' -
  . . . . . .
   . . . . .
    @ . . .

The solution works by maintaining an invariant at the beginning of each iteration that the current memory cell zero or negative (current number - 100 on all iterations except the first one) and the cell to the left is the current number.

Solution's memory

  • &! copies current number from the cell to the left (due to the memory invarant) and prints it

  • ) increments current cell, so it will be current number for the next iteration

  • { moves to the memory cell to the left, pointing towards two cells with zeros

  • & copies zero from one of those cells into current cell

  • )0; sets current cell value to 10 (ascii code for newline) and prints it

  • 0 sets current cell value to 100 = 10 * 10 + 0

  • ' moves to the memory cell to the back right without turning memory pointer around, so now it points towards next number to the left and 100 to the right.

  • - computes next number - 100

  • Finally pointer leaves the right corner while moving to the right, so it wraps around to the top row if next number - 100 is zero or negative, or to the bottom row otherwise where it terminates at @.

Golfed solution fits everything into a hexagon with side 3 by taking advantage of changing instruction pointer's direction, grid wrapping and idempotency of - operator.

I don't know if a solution with side 2 (7 cells) is possible, but this solutions uses 9 different operators without counting the ones that control direction, so it definitely won't fit. A more optimal side 3 solution might also be possible.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf! This is an excellent answer, with a great explanation of the workings. I hope to see more from you in future! \$\endgroup\$ Nov 19, 2023 at 12:48
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\$
0
\$\begingroup\$

Rust, 35 bytes

||for c in 0..b'e'{println!("{c}")}

Attempt This Online!

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

C# .NET 4.7.2

With 0, 47 bytes

for(int i=0;i<=0xA*0xA;)Console.WriteLine(i++);

Without 0, 59 bytes

for(int i='a'-'a',j='r'-'@';i<=j+j;)Console.WriteLine(i++);
\$\endgroup\$
0
\$\begingroup\$

Commodore C64 BASIC (THEC64, Ultimate64) 36 PETSCII characters

This can be done as a zero liner in direct mode in Commodore C64 BASIC. It relies on the default value of memory location zero being 47, so this will produce different results on other Commodore machines even though the have the same or a very similar interpreter, and the results will be different on the C128 in C64 mode too in some cases. The screen shot shows a proper representation, but {PI} is the PETSCII Pi symbol in my example, and upper case letters are shifted PETSCII graphics for keyword abbreviations.

x%={PI}+{PI}:fOi=.topE(.)+pE(.)+x%:?i;:nE

Commodore C64, make a listing to print out 0 - 100 inclusive without the characters 1 - 9 inclusive

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

Commodore 64 = 27 Bytes

0FORO=.TO{PI}+{PI}*{PI}*{PI}*{PI}:PRINTO;:NEXT

enter image description here

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

Scratch, 104 bytes

Try it on Scratch!

Requires list x to be visible, which is the norm by default on creation.

define
delete all of[x v
repeat(join(<not<>>+())(join(()+())(()+(
add((item[last]of[x v])+<not<>>)to[x v

enter image description here

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

COMMODORE 64 (improved version) = 25 Bytes

0fOI=ATOA♥("-"):?I:nE

0 FORI=ATOASC("-"):PRINTI:NEXT

"-" = Character 100

To get the correct character in the code you have to poke it in first with POKE2061,100.

\$\endgroup\$
1
  • \$\begingroup\$ You can edit your entries with improved versions that have fewer bytes, leaving your old answer below. Please consider formatting your answers as the standard used by other answers. \$\endgroup\$ Nov 17, 2023 at 16:30
0
\$\begingroup\$

vemf, 5 bytes

0,│d↨

cancats 0 and the integers on [1, 100]

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

Morsecco 59 60 bytes

Avoiding digits is not really challenging in a language without digits, but I found it interesting which strategy would give the shortest code.

The straight forward loop takes 66 bytes:

. . -- - - - -.- -. --- . - .- - - . .--..-.- .- --.. --. - .- --.
  • . . to Enter 0
  • -- - to Mark the current program position
  • - - -.- -. dup and Konvert to Number
  • --- to Output
  • . - .- to Enter 1 and Add
  • - - . .--..-.- .- dup, Enter -101 and Add
  • --.. --. to Zeroskip until next --.
  • - .- --. drop the unused difference and Go to marked position

Two more bytes can be saved by using an empty token as target for the Zeroskip (note the essential trailing space!): . . -- - - - -.- -. --- . - .- - - . .--..-.- .- --.. - .- --. (64 bytes)

Counting down is usually cheaper, but here we need to concatenate the numbers to a string to show them in the correct order (70 bytes):

.    . --..-.- -- - . .- .- - - - .. -.-. .. - . --..  --.  -.- -. ---
  • . to Enter an empty cell on the stack as the string to build
  • . --..-.- to Enter 101 so we can start the loop by decrementing
  • -- - to Mark the start of the loop
  • . .- .- decrement by Adding -1
  • - - - .. -.-. .. dup, rot the string to the top and Concatenate the cells with a space in between
  • - . --.. --. swap to get the index to the top and do a Zeroskip the the Go command that closes the loop
  • -.- -. --- to Konvert the whole string to Number and Output

An unusual trick takes us down to 61 bytes: Counting up from -101 to 0 and directly outputting the index+101:

. .--..-.- -- - - - . --..-.- .- -.- -. --- . - .- --..  --. 

I found no way to mitigate Entering the 101 twice without wasting the bytes for stack juggling.

Finally, the best solution with 60 bytes turned out to be defining a recurive command (I used the undefined command -.):

.   - - --.. -. . .- .- -. -.- -. ---  . -. .-- . --..-.. -.
  • . [command] . -. .-- to Enter the command and Write it to address -.
  • . --..-.. -. to Enter 100 and call the new command
  • The command itself is
    • - - --.. -. dup and Zeroskip to the self-calling -.
    • . .- .- decrement by Adding -1
    • -. call itself with the decremented value
    • -.- -. --- to Konvert to Number and Output. As this is done after calling itself, it is done first for the 0 case, to resorting is done automatically

eXecuting the command directly from the stack . --..-.. . - - --.. -..- . .- .- . .- -..- -.- -. --- -..- save nine bytes for saving the command, but wastes three time the two bytes that -..- is longer than -. and five more bytes for placing .- on the stack to eXecute Again, ending in 62 bytes.

I hope this illustrates why I like morsecco as a golfing language: There are many ways to do something and a lot of tricks to discover. The pure score is not impressing, but considering that you could pack 5 characters into one byte (3^5 = 243 < 256), 12 true bytes even beat some golfing languages!

\$\endgroup\$
1 2 3 4 5
6

Your Answer

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