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 communityPrint 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.
òL
Calls the function ò
on the variable U
with the variable L
as an argument. U is 0 when the program has no input, L is 100 whenever a program starts, and the function ò returns the inclusive range from "this" (U) to its first argument (L).
Also valid:
Lò
Calls the function ò
on the variable L
with no arguments. With no arguments ò
returns the inclusive range from 0 to "this". This one ignores input, rather than requiring no input.
-h
, 2 bytesPS. You need to hand-type that flag because the permalink for flags is not working.
0|
0 # 0
| # concatenated with
# (implicit) the range [1 .. 100]
Implicit output
Edit: From 31 bytes to 19 bytes, thanks to @binarycat's suggestion of using fromEnum
instead of ord
, which requires the Data.Char package.
Are imports cheating?
l=[0..fromEnum 'd']
Convert 'd' into it's ASCII integer value using the fromEnum
function, which gives 100 and generate a list from 0 to 100.
fromEnum
will do just fine.
\$\endgroup\$
Mar 7, 2021 at 23:49
let i=0;while(true){console.log(i);if(i.toString().includes('00'))break;i++;}
,.Puck,.Ajax,.Act I:.Scene I:.[Exeunt][Enter Puck and Ajax]Puck:Open heart.You is the sum ofyou a cat.Ajax:You is twice the sum ofa big big cat a cat.Speak mind!You is the square ofyou.Is I nicer you?If notlet usAct I.
This is a golfed version based off of Dr Lemniscate's answer, with several non-trivial modifications, such as using only one Scene and not initialising characters. This also includes the character and program introduction section, which was neglected.
,.Puck,.Ajax,.Act I:.Scene I:. # Introduce the characters and the play itself.
[Exeunt][Enter Puck and Ajax] # Enter the main characters
Puck: Open heart. # Print Ajax's value as a number
You is the sum ofyou a cat. # And increment it
Ajax: You is twice the sum ofa big big cat a cat. # Set Puck to 2*(8+2)=10
Speak mind! # Print as a character (a newline)
You is the square ofyou. # Square the value to 100
Is I nicer you? # Compare the value against Ajax's
If notlet usAct I. # And loop if the value is <= 100
for(i=0;!print(i)>=~-(''+i++).length;);
Thanks Jo king
for(i=0;i<=(c=" ".length)*-~c*-~c;)print(i++)
Not the shortest by any margin
for(i = 0; // simple for loop
i <= (c=" ".length)*~-c*~-c;
// c = " ".length ---> 4
// * -~c * -~c ---> -~c => 5 => 4 * * 5 * 5 ==> 100
;)print(i++) ---> end for loop and print i, then increment by 1
_=>[...Array((c=" ".length)*-~c*-~c).keys()]
That prints up to 99 for 51 bytes,
_=>[...Array((c=" ".length)**~-~-c-c*c).keys()]
Prints upto 100 but byte count is 54.
END{for(i;i<=0xA**2;)print i++}
-1 byte thanks to me
-3 bytes thanks to @cnamejj
i=0
statement since AWK uses an initial value of 0 for any variable use in a mathematical expression before it's set.
\$\endgroup\$
0xA**2
saves another byte. (I tried to edit the previous comment but wasn't able too since more than 5 mins had passed.)
\$\endgroup\$
v(>)>(^)v(^^^>^^)S(^>>^)>(>)L(>)<<<v((>))>(^)<<>(>)B(>)
A version with an explanation:
[You actually do need to inititalize address 0, my mistake. Also, my original version did not print 0.]
v(>) [Inititalizes address 0]
>(^) [Sets address pointer to 1, this is where the space character wil be held]
v(^^^>^^) [Writes 32 (a space) to memory]
S(^>>^) [Sets the comparison buffer to 101]
>(>) [Back to address 0]
L(>) [Loop marker]
<<< [Output the counter at address 0 as a number]
v((>)) [Increase the counter by 1]
>(^) [Goes to the space]
<< [Output the space]
>(>) [Back to 0]
B(>) [Done!]
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\$
'ei,:p
'e e# Push character "e" (which has code point 101)
i e# Convert to integer. Gives 101
, e# Range (non-inclusive, starting at 0). Gives [0 1 2 ... 100]
:p e# For each entry: print with newline
@hakr46's solution
Uh*TT
original:
U+*TT^Z
Outputs a list. If the separator must be a single character, 11 bytes 6 bytes
My first golf. Pretty happy about it! Makes use of the fact that anything to the power of 0 is 1.
-3/5 bytes thanks to @hakr46 :D
h
. Also, separating a list by newlines is done with j
with only one argument. These let you save 3 bytes to output the list or 5 bytes to output each number with a single character separator.
\$\endgroup\$
Seq.iter(printfn"%A"){0..(int 'd')}
(Too bad it wasn't only to 99, could have gotten rid of the Seq.iter
due to printing truncation...)
Hr,n[lon]
Hr - Push range(0,100)
, - Reverse stack
n - Print the 0
[ ] - While not zero:
lon - Print a newline and the next number
<?=join(',',range(0,ord(d)));
Explanation
ord(d) // return integer value of ASCII character 'd'
range // create array from A to B, inclusive
join // glue array values together using comma as separator
<?= // output
included more for the amusing built-in than the byte count, though this would be something like 9 bytes in the hypothetical mthmca golfing language.
Range[0,FromRomanNumeral@"C"]
And similar, but longer
Range[0, Interpreter["SemanticNumber"]@"hundred"]
f()
the second time should print 0~100 again.
\$\endgroup\$
puts 0
. Still shorter.
\$\endgroup\$
Feb 25, 2021 at 20:18
SELECT number FROM spt_values WHERE number<ASCII('e')AND'P'=type
The master
database on any SQL server contains a system table called spt_values
that (among other things) contain the numbers 0 to 2047. To cap the output I used ASCII('e')
, which is 101.
Let me know if you know of a shorter way to generate the number 100 or 101.
)
touch the AND
keyword just as '
touches it? Because rewriting the expression as number<ASCII('e')AND'P'=type
could save 1 character.
\$\endgroup\$
Feb 25, 2021 at 21:17
v->java.util.stream.IntStream.range(0,'e').forEach(System.out::println)
.doSomething(v->{...})
. So the Type name =
form i not specific to the lambda. What is specific to the lambda is the param -> ...
, hence the wide usage of lambdas in Java answers here on codegolf.
\$\endgroup\$
Feb 26, 2021 at 9:57
alert([...Array(0xB0F-0xAAA).keys()])
for(n=0;n+n<0xCA;)alert(n++)
.keys()
before!
\$\endgroup\$
Feb 27, 2021 at 21:49
Sorry I overread that it's not allowed to use the characters 1-9.
I think it is really stupid to say my language can this is a shorter way, because every language today contains more than a bunch of foreign frameworks. IMHO this "bytes" should be added to the real bytes you need to print values from 0 to 100 on the screen. Therefore a good old Atari 600XL with 16kib of RAM only need: 22 bytes. No other Software is need everything is build in.
Switch the hardware on, wait 2-3sec and type: f.a=0toasc("d"):?a:n.a
'f.' is an allowed shortcut for 'for' and 'n.' is a shortcut for 'next'
Maybe the C64 need also such less bytes.
Everything else need megabytes of extra hidden bytes.
JM2C
for a=0 to asc("d"):?a:next
while(a<asc("e")):?a:a=a+!0:wend
Of course, a FOR loop is shorter than using WHILE. Thanks Lars for your example.
My earlier (apparently invalid) attempt, which got downvoted for not stopping at 100:
0 ?a:a=a+!0:goto 0
I'll leave it here for completeness - only 18 bytes though.
Now this is not going to beat some volcano in New Zealand either... that said, it would work on 8-bit computers where the entire language interpreter was on a ROM that might be 2-16 KILObytes for the whole thing. Every bytes counted (like code golf) - there certainly wasn't space to add topographical data for the developer's favourite mountain range. 😂
char e false [do] [i] . [loop]
commented:
char e \ ascii value 101
false \ 0
[do] \ loop a fixed number of times
[i] \ retrieve the iterator value
. \ print the top of the stack as a number, followed by a space
[loop] \ end of loop
'e
instead of char e
, and 0 is allowed in the challenge.
\$\endgroup\$
'e
isn't standard. I already made another post that uses zero.
\$\endgroup\$
Mar 7, 2021 at 23:58
char e 0 [do] [i] . [loop]
commented:
char e \ ascii value 101
0
[do] \ loop a fixed number of times
[i] \ retrieve the iterator value
. \ print the top of the stack as a number, followed by a space
[loop] \ end of loop
func main:
.local a : obj
push 0
pop a
inc a
inc a
push a
inc a
inc a
inc a
push a
mul
dup
mul
pop a
lda 0
.lbl a
inc $a
push $a
dup
print.n
push a
sub
brtrue a
ret
end
Commented and ungolfed:
func main:
.local onehundred : obj
; Calculate 100
push 0
pop onehundred
inc onehundred
inc onehundred
push onehundred
; Stack: [ 2 ]
inc onehundred
inc onehundred
inc onehundred
push onehundred
; Stack: [ 2, 5 ]
mul
; Stack: [ 10 ]
dup
; Stack: [ 10, 10 ]
mul
; Stack: [ 100 ]
pop onehundred
lda 0
.lbl loop
; Print $a
inc $a
push $a
dup
print.n
; Zero is falsy. Check if $a - 100 == 0
push onehundred
sub
brtrue loop
ret
end
0
. Which is what makes this challenge interesting, IMO. \$\endgroup\$