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 communityF:volcano
The sequence operator :
coerces its arguments to integers. F
is the boolean FALSE
, which gets coerced to 0
. volcano
is one of the many built-in datasets (it gives topographic information about Maunga Whau in New Zealand); since it is a matrix, :
fetches the value at position [1, 1]
which is luckily equal to 100
. The code is therefore equivalent to 0:100
.
This answer was inspired by a conversation with Giuseppe and Kirill L. in the comments under Giuseppe's R answer.
volcano
specifically about Maunga Whau in New Zealand?
\$\endgroup\$
Feb 23, 2021 at 20:27
volcano
is the only dataset whose first entry is in \$[100, 101)\$. Using anything else than the first entry leads to at least 9 bytes, even for a dataset with a 3-character name (e.g. sum(BOD)
or npk[pi]
, which don't give 100 anyway). I don't think it can get shorter using this approach.
\$\endgroup\$
Feb 24, 2021 at 7:08
Thanks to caird coinheringaahing for -4 bytes, ovs for -3 bytes
print(*range(*b'e'))
I'm pretty poor at golfing, so there's probably a better way to do this.
ord('e')
with *b'e'
for -3 bytes.
\$\endgroup\$
for char in b'hello': print(char)
\$\endgroup\$
Feb 23, 2021 at 16:08
We cannot write \$100\$ or \$101\$ in hexadecimal with 0's and letters only (0x64 and 0x65 respectively), but we can write \$202\$ (0xCA) and use \$2n<202\$ as the condition of the for
loop.
for(n=0;n+n<0xCA;)print(n++)
This version computes \$10^2\$ with the hexadecimal representation of \$10\$.
for(n=0;n<=0xA*0xA;)print(n++)
This version builds the string "100"
.
for(n=0;n<=-~0+'00';)print(n++)
for(n=0;n<=0xA+'0';)print(n++)
.
\$\endgroup\$
Feb 27, 2021 at 8:46
>>++++++++++<<++++++[>>>++++++++<<<-]++++++[>>>>++++++++<<<<-]++++++++++>++++++++++<[>[>>.>.+<<.<-]++++++++++>>>----------<+<<<-]>>>>+.-..
No numbers is pretty easy, but the golf size is not great... :)
I am sure it can be improved, I am really a beginner in using Brainfuck. I wanted to try it anyway.
How it works:
>>++++++++++<< LF Char (idx2)
++++++[>>>++++++++<<<-] Zero char tens (idx3)
++++++[>>>>++++++++<<<<-] Zero char unit (idx4)
+++++ +++++ 10 counter (tens)
>+++++ +++++< 10 counter (unit)
[> Move to the counter
[>>. Print the tens
>.+ Print the unit and increment
<<. Print the LF
<-] Loop 10 times
+++++ +++++ Restore the counter
>>>----- ----- Restore the digit
<+ Increment the tens char
<<<-] Loop everything 10 times
>>>>+.-.. Print 100 using a cell which is already at char 0
³Ż
Outputs a list. If the separator must be a single character, 3 bytes
³ŻK - Main link. Takes no arguments
³ - Yield 100
Ż - Range from 0 to 100
K - Join by spaces (optional)
83 D2
(and 4B
for the 3 byte version). Jelly uses a custom code page to encode its programs in order to make them more "readable", but if you fed a raw byte stream of those two bytes into the Jelly interpreter, it would produce the same output
\$\endgroup\$
Feb 26, 2021 at 15:45
@not
@mov acc dat
@not
tgt acc dat
-mov acc p0
-add x0
slp x0
Outputs 0-100 as simple output, one per time unit. Makes use of the DX300 (XBus <-> Simple Input chip) and LC70G04 (NOT gate), which cost 1¥ each but do not use any power or count as lines of code (the game's measure of code length). These are used to generate a value of 1, which it adds and outputs until it hits 100. The value for 100 is generated using the "not" command, which makes the accumulator 100 if it is value 0, otherwise it sets the acc to 0.
(Not pictured: conversion from simple output to the screen's XBus input, for the visualization.)
@not | not
@mov acc p0 | mul acc
@mov acc dat | dgt 0
@not | sub p0
add p0 | dgt 0
tgt acc dat | mul acc
-mov acc x0 | mov acc p0
slp p0 | slx x0
Outputs 0-100 as one XBus output each. Uses only programmable MCxxxx chips, no logic gates or other components. Generates value 1 in a pretty interesting way:
not # acc = 100
mul acc # 100 * 100 = 999 (max value)
dgt 0 # digit 0 of 999 = 9
sub p0 # 9 - 100 = -91
dgt 0 # digit 0 of -91 = -1
mul acc # -1 * -1 = 1
put 0..Ⅽ
Ⅽ
here is the Unicode character ROMAN NUMERAL ONE HUNDRED.
Any other Unicode character with a defined value of 100 could be used:
௱: TAMIL NUMBER ONE HUNDRED
൱: MALAYALAM NUMBER ONE HUNDRED
፻: ETHIOPIC NUMBER HUNDRED
ⅽ: SMALL ROMAN NUMERAL ONE HUNDRED
佰: CJK UNIFIED IDEOGRAPH-4F70
百: CJK UNIFIED IDEOGRAPH-767E
陌: CJK UNIFIED IDEOGRAPH-964C
All are three UTF-8 bytes long, like Ⅽ
.
0..foo
, you can use ^foo
. So you can get 8 bytes with put ^Ⅽ
\$\endgroup\$
Feb 24, 2021 at 3:08
^foo
is the same as 0..(foo-1)
, not 0..foo
.
\$\endgroup\$
puts ^
then the character would save bytes
\$\endgroup\$
Mar 5, 2021 at 0:51
F:(0xA*0xA)
F:0xA^(T+T)
Uses this tip.
Still being beaten by some volcano in New Zealand, though...
Old answer:
F:paste0(+T,0,0)
Thanks to Kirill L. for correcting an error.
R's ASCII=>byte function is utf8ToInt
, which unfortunately has an 8
in it. Luckily, :
will attempt to coerce its arguments to numeric types, so we construct 100
by pasting together +F
(which coerces its value to 0
) and two 0
s. This would also work, though longer, without a 0
as F:paste(+T,+F,+F,sep="")
.
Possibly there's a very short builtin dataset with a sum
that's close to 100, though I haven't been able to find one.
F
rather than T
.
\$\endgroup\$
Feb 23, 2021 at 17:19
F:sum(T|Nile)
is still only 13 bytes.
\$\endgroup\$
Feb 23, 2021 at 17:48
volcano
dataset leads to a 9 byte answer, which I posted instead.
\$\endgroup\$
Feb 23, 2021 at 19:34
jHRM
, 0 bytes
Kinda cheating, but whatever.
# full program
# H flag presets the stack to 100
# R flag does range when number is treated as iterable
# M flag makes range start at 0
# j flag joins the top of the stack by newlines
,,
,,,,,,
,
,,,,,
$.`
Try it online! Explanation: The first stage inserts two commas, which the second stage increases to 20 (it's complicated). The third stage multiplies by 5 to give 100. The last stage then inserts the number of commas so far at each position.
0514150
commas for a nice symmetry!
\$\endgroup\$
$(
..)
is good coding habit, but is longer than `
..`
. And no need to quote ”%d” as contains nothing special. In change the “'d” contains character with special meaning, but only one, so escaping it with \
is shorter. Try it online!
\$\endgroup\$
Feb 23, 2021 at 16:23
'd
? I assume printf is interpreting it as its ascii numeric value but I don't see it mentioned in the docs.
\$\endgroup\$
printf
specification's Examples section. Maybe Wasif knows a better documentation.
\$\endgroup\$
Feb 23, 2021 at 16:35
f(i){for(i=0;printf("%d ",i++)&'#';);}
Without using digit 0
, it would be 39 bytes: i;main(){for(;printf("%d ",i++)&'#';);}
printf
returns how many bytes are printed. '#'
is as same as number 35 (ASCII 35 for "#"). That's all you need to know to make it work.
\$\endgroup\$
-23 bytes thanks to Bubbler
0xa sq [0,b] [ . ] each
I've never written anything in Factor before, but it's a surprisingly fun language.
each
on it without >array
. 3) There are multiple ways to get the constant 100, such as CHAR: d
or 0xa sq
. If you want, drop by the Factor chatroom, and I'll explain things further :)
\$\endgroup\$
jH
, 1 byteʀ
Flags for the win. The H
flag presets the stack to 100, generate range 0 to 100 and then j
flag joins on newlines. The flag was around before this challenge too.
First time golfing, I hope I posted this right!
while($q<ord(e))echo+$q++,' ';
Thanks to manatwork and Dewi Morgan's suggestions to improving the code! From 34 to 30 bytes!
The code revisions are in the edit history, removed here so it looks cleaner!
echo
's argument. I would suggest this: Try it online!
\$\endgroup\$
Feb 24, 2021 at 6:08
$q=0
because null isn't being cast to an int. We can cast to an int to avoid it, but (int)
takes 5 bytes. But adding 0 casts to 0, and we can only do that in 2 bytes, though we need to re-add the space after the echo, so it's effectively 3. Still saves us a byte, though! while($q<ord(e))echo 0+$q++." ";
(while has the same bytecount as for with just the middle clause used).
\$\endgroup\$
Feb 25, 2021 at 17:22
*
operator will do it instead of .to_a
: p *0..?d.ord
\$\endgroup\$
Feb 23, 2021 at 16:00
.ord
\$\endgroup\$
$,=",";
, but you need ord('d')
for it to work.
\$\endgroup\$
Feb 23, 2021 at 16:03
perl -E 'say 0..ord(d)'
\$\endgroup\$
say for 0..ord d
would meet the rules.
\$\endgroup\$
2071 bytes
o{i}c{d}io{i}dc{d}iio{i}ddc{d}iiio{i}dddcddddddoiiiiiicdddddoiiiiicddddoiiiicdddoiiicddoiicdoicociodciioddciiiodddciiiioddddciiiiiodddddciiiiiioddddddc{i}dddo{d}iiic{i}ddo{d}iic{i}do{d}ic{i}o{d}c{i}io{d}dc{i}iio{d}ddc{i}iiio{d}dddc{i}iiiio{d}ddddc{i}iiiiio{d}dddddc{i}iiiiiio{d}ddddddc{i}{i}dddo{d}{d}iiic{i}{i}ddo{d}{d}iic{i}{i}do{d}{d}ic{i}{i}o{d}{d}c{i}{i}io{d}{d}dc{i}{i}iio{d}{d}ddc{i}{i}iiio{d}{d}dddc{i}{i}iiiio{d}{d}ddddc{i}{i}iiiiio{d}{d}dddddc{i}{i}iiiiiio{d}{d}ddddddc{i}{i}{i}dddo{d}{d}{d}iiic{i}{i}{i}ddo{d}{d}{d}iic{i}{i}{i}do{d}{d}{d}ic{i}{i}{i}o{d}{d}{d}c{i}{i}{i}io{d}{d}{d}dc{i}{i}{i}iio{d}{d}{d}ddc{i}{i}{i}iiio{d}{d}{d}dddc{i}{i}{i}iiiio{d}{d}{d}ddddc{i}{i}{i}iiiiio{d}{d}{d}dddddc{i}{i}{i}iiiiiio{d}{d}{d}ddddddc{{i}dddddd}dddo{{d}iiiiii}iiic{{i}dddddd}ddo{{d}iiiiii}iic{{i}dddddd}do{{d}iiiiii}ic{{i}dddddd}o{{d}iiiiii}c{{i}dddddd}io{{d}iiiiii}dc{{i}dddddd}iio{{d}iiiiii}ddc{{i}dddddd}iiio{{d}iiiiii}dddc{{i}dddddd}iiiio{{d}iiiiii}ddddc{{i}dddddd}iiiiio{{d}iiiiii}dddddc{{i}dddddd}iiiiiio{{d}iiiiii}ddddddc{{i}ddddd}dddo{{d}iiiii}iiic{{i}ddddd}ddo{{d}iiiii}iic{{i}ddddd}do{{d}iiiii}ic{{i}ddddd}o{{d}iiiii}c{{i}ddddd}io{{d}iiiii}dc{{i}ddddd}iio{{d}iiiii}ddc{{i}ddddd}iiio{{d}iiiii}dddc{{i}ddddd}iiiio{{d}iiiii}ddddc{{i}ddddd}iiiiio{{d}iiiii}dddddc{{i}ddddd}iiiiiio{{d}iiiii}ddddddc{{i}dddd}dddo{{d}iiii}iiic{{i}dddd}ddo{{d}iiii}iic{{i}dddd}do{{d}iiii}ic{{i}dddd}o{{d}iiii}c{{i}dddd}io{{d}iiii}dc{{i}dddd}iio{{d}iiii}ddc{{i}dddd}iiio{{d}iiii}dddc{{i}dddd}iiiio{{d}iiii}ddddc{{i}dddd}iiiiio{{d}iiii}dddddc{{i}dddd}iiiiiio{{d}iiii}ddddddc{{i}ddd}dddo{{d}iii}iiic{{i}ddd}ddo{{d}iii}iic{{i}ddd}do{{d}iii}ic{{i}ddd}o{{d}iii}c{{i}ddd}io{{d}iii}dc{{i}ddd}iio{{d}iii}ddc{{i}ddd}iiio{{d}iii}dddc{{i}ddd}iiiio{{d}iii}ddddc{{i}ddd}iiiiio{{d}iii}dddddc{{i}ddd}iiiiiio{{d}iii}ddddddc{{i}dd}dddo{{d}ii}iiic{{i}dd}ddo{{d}ii}iic{{i}dd}do{{d}ii}ic{{i}dd}o{{d}ii}c{{i}dd}io{{d}ii}dc{{i}dd}iio{{d}ii}ddc{{i}dd}iiio{{d}ii}dddc{{i}dd}iiiio{{d}ii}ddddc{{i}dd}iiiiio{{d}ii}dddddc{{i}dd}iiiiiio{{d}ii}ddddddc{{i}d}dddo{{d}i}iiic{{i}d}ddo{{d}i}iic{{i}d}do{{d}i}ic{{i}d}o{{d}i}c
8 bytes (if you consider Hello, world! a valid separator)
o{{iow}}
7 bytes (If you don't care about seperators)
o{{io}}
Never thought I'd see deadfish be shorter than, well, anything except Unary.
=Range[0,LL
-1 byte from Imanton1
Mathematica interprets the =
prefix as a call to Wolfram Alpha (auto-converting it to the orange glyph seen below), which in turn interprets "LL" as a Roman numeral for 100. I used "LL" because this doesn't work with the shorter "C".
=Range[0,hecto
\$\endgroup\$
Oct 17, 2021 at 18:36
print(*range(*b'e'))
How it works?
Basically, doing *b'char' is equivalent to ord('char'), and in this case ord('e') is equal to 101 ;
Lets re-create the ord() function!
ord=lambda x:(int(*bytes(x, 'ascii')))
As you can see it works! You can test this yourself here.
print(*range(0xa*0xa-~0))
How it works?
0xa = 10, ~0 = -1, -~0 = 1 (equivalent to -1*-1)
'utf8'
contains an 8
.
\$\endgroup\$
Oct 29, 2021 at 12:24
i=0-#"0"repeat i+=#"0"?i
until#tostr(i)>#"00"
-5 bytes by replacing print
with its shorthand, ?
.
Demo (50 byte version; 45 byte version has same output):
⎕←0,⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬
≢⍬⍬⍬⍬ ⍝ This evaluates to 4
≢⍬⍬ ⍝ This evaluates to 2
⍳≢⍬⍬⍬⍬ ⍝ Evaluates to 1 2 3 4
(+/⍳≢⍬⍬⍬⍬) ⍝ Sums up previous list, 1+2+3+4 = 10
(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Exponentiates previous result by 2
⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Generates 1 2 ... 100
0,⍳(+/⍳≢⍬⍬⍬⍬)*≢⍬⍬ ⍝ Appends 0 to front
for i=0,0xA*0xA do print(i)end
d='d'for O=0,d:byte()do print(O)end
- 35 bytes. Slightly different approach.
\$\endgroup\$
{for(;a<=0xa*0xa;)$a=a++}a
Thanks to xnor for pointing out a brainfart (since fixed) in the original
This works by using 0xa*0xa
to compute 100, then assigns each positional variable to it's own sequential number. Then the a
without a code block (evaluates as truthy since a
is 100) prints all the positional arguments separated by a space.
To be honest, I'm not 100% sure why the 0
prints but it does. :)
0
. Which is what makes this challenge interesting, IMO. \$\endgroup\$