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#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!
\newcount~\loop\advance~`^^A\the~ \ifnum~<`^^%\repeat\bye
Makes uses of these two tricks:
^^A
becomes NUL
.'e'{}/,`
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'{}/,' '*
Solution:
!"e"
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
#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\$.
\001.r.-.z.c.n,.o\001.+.ce.a
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.e
.c.w\001.-.e.+.n .o.d.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.
Slashes only:
/\\\\\/\//\\\/\/\/\/\/\/\/\/\/\/\/\///\/\\\/\/\//\\\/\\\\\/\\\\\\\/\\\\\\\\\\\/\/\\\\\\\/\\\/\\\/\\\\\\\\\\\/\/\/\\\/\\\/\\\\\\\\\\\/\/\\\\\\\/\\\\\\\\\\\/\/\/\\\/\//\\/\\\\\\\\\\\//
x=True;a=x+x;b=a*a+x;print(*range(a*a*b*b+x))
Thanks to Jo King for saving 8 bytes
0Z@#@'d<l+[.a?l-z
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" }
'dR&u
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
'dR&u
is 5 bytes using implicit 0 and the R
ange command.
\$\endgroup\$
package main
func main(){for i:=' ';i<'';i++{println(i-' ')}}
Upper bound for the loop has value 133 NEXT LINE (NEL)
. Separator is newlines. Prints to STDERR.
('P'..'´').joinToString(","){""+it.minus('P')}
Saving two bytes by using other chars from the ascii table that only takes one instead of two bytes.
('\n'..'n').joinToString(","){""+it.minus('\n')}
Using the ascii table to get those numbers.
When brackets are allowed at the start and end then this is smaller:
('P'..'´').map{it.minus('P')}
0::naoaa*(?!;ba-+!
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
0S^ThhZ
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.
for x in range(ord("e")):print(x)
@set/ax=0xb-0xa
@for /l %%b in (0,%x%,%x%00)do @echo %%b
-61 bytes for @Neil
set/ax=0xb-0xa
to set x
etc.
\$\endgroup\$
y
at all, just use %x%00
in its place.
\$\endgroup\$
set/a
or )do
, and you can remove the @echo off
and use @set
, @for
and @echo
instead.
\$\endgroup\$
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 :)
_
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\$
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.
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
0
. Which is what makes this challenge interesting, IMO. \$\endgroup\$