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.
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.Sign up to join this community
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:
cmd.exe's command line using:
@Set /A s=0xa*0xa&@Echo(0 @For /l %%i in ()Do @If !a! LSS !s! @(Set/A a+=0xb-0xa&echo(!a!)Else Exit
uses an infinite for /l loop and hex values to increment by
loop is broken when
10x10=100] is reached
# // 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
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\$.
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
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
/\\\\\/\//\\\/\/\/\/\/\/\/\/\/\/\/\///\/\\\/\/\//\\\/\ \/\\\\\\\/\ \\\/\/\\\\\\\/\\\/\\\/\\\\\\\\\\\/\/\/\\\/\\\/\\\\\\\\\\\/\/\\\\\\\/\ \\\/\/\/\\\/\///\\\\\\\\\\\//
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.
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):
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
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 :)