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 community0:double('d')
The ASCII code for lowercase d is 100, so convert to a double and go from 0 in intervals of 1 with ":"
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]
Thanks to
[zpdA0>x]dsxx
Thanks to
[zpzA0!<m]dsmx
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
i0<esc><C-A>s<C-R>=range(<C-R>"0<C-R>")
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
.
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
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\$
Apr 26, 2021 at 14:03
^+++(###....+###....+++<..#+...-....###+.@#+...$)+).>+++.$#+...^##=.+###.-#+....+)<++(-+##++>
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.
You didn't clarify that I must separate each with exactly one character, so here it is mine.
print length uc xor s qq q xor print while length ne ord qw q eq
# print(length) did not work for zero as $_ is not defined at then
print length uc xor
s qq q xor
# delimiter
print
while
# equals to: length ne 101
length ne ord qw q eq
seq `dc<<<A0Kf`
Previous answer:
eval echo {0..$[++x]00}
seq
's parameters. Sorry, that looks like +1 character. ☹
\$\endgroup\$
Feb 23, 2021 at 20:28
seq `dc<<<A0Kf`
.
\$\endgroup\$
Feb 23, 2021 at 20:31
eval echo {0..$[++x]00}
\$\endgroup\$
Oct 29, 2021 at 7:40
Thanks to Redwolf for -1 byte, Unrelated String for -4
||for i in 0..b'e'{print!("{} ",i)}
||(0..b'e').all(|i|print!("{} ",i)==())
||(0..b'e').for_each(|i|print!("{} ",i))
i
in the print!
?
\$\endgroup\$
Oct 30, 2021 at 22:12
for(a of Array("e".charCodeAt()).keys())alert(a)
Can be shorter, if you allow in reverse (36 chars)
for(i="e".charCodeAt();--i;)alert(i)
range("e"|explode[])
Sample run:
bash-5.0$ jq -n 'range("e"|explode[])' | head
0
1
2
3
4
5
6
7
8
9
!0+"e"
Uses 0+
to convert "e"
to an integer, then takes the range from 0 up to, but not including, that value (101).
i+R`c0c0$[+i]~
i prints the value at the top of the stack (0)
+ adds 1 to the value on top of the stack (which was 0, is now 1.0)
R` reformats the top of the stack with the arg ` (the value at the top of the stack).
since ` = 1, it reformats the top of the stack as the integer 1
c0c0 concatenates the value in storage at the current pointer (=0) to the top of the
stack twice, resulting in "100"
$ swaps the value on top of the stack (100) with the value in storage at the
current pointer (0)
[ .... ]~ loop structure: loops ~ times, where ~ = value_in_storage_at_pointer = 100
+ adds one to the value on top of the stack
i prints the top of the stack as an integer
Note: the above code is based on version 1.0.* of Rattle. With the newest update (1.1.0), the code could be shortened to the following snippet (12 bytes) because the addition operator will now keep the top of the stack the same type (in this case, an integer) if possible.
i+c0c0$[+i]~
Another in the theme of "this language doesn't even care about digit characters".
The program with comments:
[Push 0
][Label
][Dup
][PrintNum
][Push 10
][PrintChar
][Push 1
][Add ][Dup
][Push 101
][Subtract ][JmpNeg
]
for i=0 to 0xa*0xa
print i
next
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 :)
p.i
for print i
?
\$\endgroup\$
$((
..))
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\$
Feb 27, 2021 at 0:12
qqYP<C-x>qi0<esc><C-a>a00@q<esc>Yxx@0
qq q Record macro q:
Y Yank the current line
P Paste a copy of it on the line above
<C-x> Decrement the number under the cursor
i0<esc> Insert a 0
<C-a> Increment it to 1
a00@q<esc> Append 00@q
Y Yank this line (100@q)
xx Delete the @q part
@0 Execute the yanked text as commands
(100@q executes the q macro 100 times)
Thanks to @Cinaski for saving 3 bytes with \!
instead of "ba"-
.
:.\!+:"d"`#@_
Uses \!
to NOT
the 0
at the bottom of the stack and uses that to increment the loop, then tests if the counter is greater than d
to end. Certainly not the shortest answer, but this is my first golf challenge, and I wanted to practice Befunge, which I decided to pick up yesterday. This is also my first time trying a stack-based language, and I'm having a lot of fun with it.
fn a()void{for(" "**'e')|_,i|{@import("std").debug.print("{d} ",.{i});}}
I've excluded the @import()
boilerplate as it seems analogous to C's #include
, which is excluded from other answers. If deemed necessary, I will add it back in.
fn a() void {
for (" " ** 'e') |_, i| {
@import("std").debug.print("{d} ",.{i});
}
}
fn a() void
Declare a function which takes no parameters and returns nothingfor () |_, i|
For every item in the array inside of ()
, iterate and capture the entree as _
(a throwaway variable) and the index as i
" " ** 'e'
Take the string (strings are slices, or pointer-arrays which know their length) and repeat it 'e'
(101) times**
Requires a little bit more more explanation I think: In Zig, there is the concept of "comptime" (compile time) and runtime. **
is an operator which repeats any array literal or slice literal at comptime, because the resulting length is still known to the compiler.@import("std").debug.print("",.{});
Print to STDERR (I believe that's valid for this question, right?), the first argument is the formatting string, and the second is an "anonymous sctruct"/tuple with a variable number of arguments in it (Zig doesn't have var-args)."{d} "
The format string. Zig denotes {}
as the formatting characters, with d
meaning a digit in this case.I did not see a rust solution, so here's my attempt:
||print!("{:?}",(0..b'e').collect::<Vec<_>>())
Thanks to @ovs for pointing out the closure variant.
The range (0..b'e')
is collected into a vector (using the placeholder _
, letting the compiler figure out the type) and printed using the debug formatter {:?}
, which "dumps" the entire vector.
The range upper bound is exclusive, and is represented using the byte literal b'e'
, which is equivalent to an u8
integer number literal; in this case 101 (e
's ASCII value).
fn main() { ... }
. Will use the closure version. Thank you for pointing this out!
\$\endgroup\$
Oct 29, 2021 at 16:06
int main(a,b){for(;a^'f';a++){printf("%d\n",a-!!a);}}
(Thanks to Jo King♦)
k;main(){for(;k^'e';)printf("%d ",k++);}
ummmmm uhhhh errrrr uhhh um errrrr um um yeah err heh but um yeah err then uh okay um err then wait
It's not the shortest.
Explanation:
push 101 ummmmm uhhhh errrrr uhhh um errrrr
push 0 to other stack um um yeah err heh
loop but ... wait
decrement um yeah err
print + increment other then uh okay um err then
i;f(){while(i<'e')printf("%d",i++);}
Ungolfed
i;
f()
{
while(i < 'e')
printf("%d", i++);
}
Explanation
Function to print numbers from 0 to 100 without digits. A global variable of type integer is created (so that it is automatically initialized to 0), the variable is incremented and printed 100 times through a loop which is executed while the variable is less than 'e' or 101 in ASCII.
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.
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:
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.
o=0
? because then you just click add slider and the output is there. but idk, should prob ask on meta
\$\endgroup\$
From left to right the commands in the command blocks are
scoreboard players operation a a += b a
tellraw @a {"score":{"name":"a","objective":"a"}}
scoreboard objectives add a dummy
scoreboard players set a a 0
execute store result score b a run data get entity @p playerGameType
The command blocks on the right set a
to 0 and b
to the playerGameType
of the player, which is 1
if the player is in creative mode.
The blocks on the left repeatedly print a
, then add b
to a
. It's stopped at exactly 100 by the piston removing the repeater powering the command block.
I'm not sure how to score this or if it's even allowed but I thought it was kind of cool.
for n in range(0, ord('e')):
print(n)
i
and print that, +=1
ing it in each iteration, then you don't need the range(0,len())
and can save some bytes.
\$\endgroup\$
Apr 17, 2022 at 3:58
for
statement
\$\endgroup\$
,
can be removed. You can see a general list of tips for python here.
\$\endgroup\$
print(*range(ord('e')))
-2 by Steffan, remove first parameter (0
) from call to range
0..[byte][char]'d'
0
. Which is what makes this challenge interesting, IMO. \$\endgroup\$