| Bytes | Lang | Time | Link |
|---|---|---|---|
| 364 | Scratch | 250723T151158Z | Rhaixer |
| 020 | Vyxal 3 | 250723T164858Z | pacman25 |
| 157 | Nim 2 | 250326T102737Z | janAkali |
| 311 | Tcl | 170212T003121Z | sergiol |
| 177 | Janet | 250511T093031Z | Adam |
| 121 | Julia 1.0 | 250326T005849Z | MarcMush |
| 029 | Pip | 250325T222328Z | DLosc |
| 208 | SAKO | 250325T195133Z | Acrimori |
| 133 | Bespoke | 250315T015958Z | Josiah W |
| 022 | Vyxal | 231106T192655Z | emanresu |
| 003 | Python | 231105T192056Z | The Empt |
| 036 | Uiua | 231105T081313Z | chunes |
| 014 | QBIC | 161026T091939Z | steenber |
| 032 | Actually | 160823T071554Z | Leaky Nu |
| 143 | BrainFlak | 161021T151225Z | Erik the |
| 088 | Factor + math.unicode | 210331T003532Z | chunes |
| 6256 | Deadfish / Deadfish~ | 210330T225217Z | emanresu |
| 267 | Elixir | 200823T115544Z | pxeger |
| 030 | Pyth | 200821T023118Z | Scott |
| 224 | Whispers v2 | 200820T182515Z | caird co |
| 300 | Java 8 | 190413T214122Z | Benjamin |
| nan | 170214T172616Z | Shaun Be | |
| 020 | MathGolf | 190329T115804Z | Kevin Cr |
| 042 | Husk | 190329T095101Z | Unrelate |
| 022 | Japt | 180529T011508Z | Bubbler |
| 059 | Excel VBA | 180420T195458Z | Taylor R |
| 044 | Processing | 170214T103522Z | user4180 |
| 146 | Lua 5.3 | 170215T161940Z | IDid |
| 071 | SmileBASIC | 170211T164336Z | 12Me21 |
| 147 | Ruby | 170215T120438Z | G B |
| 037 | PHP | 170214T121010Z | aross |
| 024 | 05AB1E | 160825T224149Z | acrolith |
| 1222 | Funciton | 151218T053155Z | Timwi |
| 205 | Racket | 161023T132819Z | rnso |
| 134 | Haskell | 160825T203803Z | Laikoni |
| 066 | Perl 5 | 151217T212607Z | Doorknob |
| 133 | Haskell | 161024T142107Z | Angs |
| 014 | Mouse2002 | 151218T005126Z | cat |
| 026 | Jelly | 160921T134644Z | Erik the |
| 035 | DC | 151217T212252Z | user1921 |
| 318 | BASH | 160826T083025Z | Sefa |
| nan | 160825T210624Z | bb94 | |
| 013 | Hexagony | 160823T131353Z | Leaky Nu |
| 078 | C | 160822T153912Z | Leaky Nu |
| 042 | J | 160301T201530Z | Conor O& |
| 194 | Ruby | 160313T013100Z | Paul Che |
| 068 | DUP | 160301T050434Z | Mama Fun |
| 026 | Jolf | 160312T231107Z | Conor O& |
| 050 | Cardinal | 160312T220658Z | M L |
| 060 | Staq | 160312T214226Z | M L |
| 5046 | beeswax | 160311T224618Z | M L |
| 123 | JavaScript | 151218T071528Z | user8165 |
| 147 | PowerShell | 151219T043743Z | Tessella |
| 089 | Hoon | 160302T212503Z | RenderSe |
| 100 | R | 160307T151639Z | slamball |
| 143 | MS Excel formulas | 160303T214148Z | dnep |
| 031 | Jelly | 160303T065241Z | ASCII-on |
| 234 | C# | 151218T024410Z | Timwi |
| 134 | Visual Basic for Applications | 160302T211022Z | dnep |
| 052 | Dyalog APL | 151218T211416Z | lirtosia |
| 295 | Haskell | 160303T060728Z | HEGX64 |
| 081 | Perl 6 | 160302T031229Z | Hotkeys |
| 068 | Visual Basic for Applications | 160302T204932Z | dnep |
| 073 | 80386 machine code | 160301T193401Z | anatolyg |
| 165 | R | 160301T172849Z | Argenis |
| 092 | Math++ | 151217T203536Z | SuperJed |
| 086 | ><> | 160301T150259Z | Aaron |
| 042 | dc | 160301T150656Z | Toby Spe |
| 3612 | ๐ผ๐๐๐๐ | 151228T232952Z | Mama Fun |
| 146 | Python 2 | 151220T215327Z | Joachim |
| 033 | Seriously | 151218T082131Z | user4594 |
| 123 | R | 151222T004740Z | mchen |
| 202 | C | 151220T224055Z | Khaled.K |
| 091 | PHP | 151218T163047Z | orp |
| 099 | Prolog | 151217T194636Z | Emigna |
| 130 | Javascript Browser Env | 151218T061838Z | rgajrawa |
| 033 | Pyth | 151218T065121Z | lirtosia |
| 098 | Marbelous | 151220T094443Z | overacto |
| 040 | Pyth | 151218T055428Z | p1xel |
| 274 | Python 2 | 151218T143730Z | แแแแ |
| 041 | k4 | 151219T084720Z | Aaron Da |
| 041 | TIBASIC | 151217T231710Z | lirtosia |
| 303 | Darkness | 151218T153444Z | sweerpot |
| 112 | D1ffe7e45e | 151217T201210Z | ASCIIThe |
| 030 | Japt | 151217T210202Z | ETHprodu |
| 036 | O | 151218T010130Z | jado |
| 159 | Javascript | 151218T145722Z | Qwertiy |
| 101 | Mathematica | 151218T132755Z | Martin E |
| 070 | Brainfuck | 151218T061144Z | p1xel |
| 024 | CJam | 151217T194602Z | Dennis |
| 030 | MATL | 151217T221805Z | David |
| 044 | dc | 151217T211834Z | Digital |
Scratch, 364 bytes
Boring straightforward solution. A few bytes can definitely be shaved by thinking more creatively.
()+( // 0, 4 bytes
()+<not< // 1, 8 bytes
<not<>>+<not< // 2, 13 bytes
(<not<>>+<not<>>)+<not< // 3, 23 bytes
(<not<>>+<not<>>)*(<not<>>+<not< // 4, 32 bytes
(join(()+<not<>>)(()+()))/(<not<>>+<not< // 5, 40 bytes
(<not<>>+<not<>>)*((<not<>>+<not<>>)+<not< // 6, 42 bytes
(((join(()+<not<>>)(()+()))-<not<>>)-<not<>>)-<not< // 7, 51 bytes
((join(()+<not<>>)(()+()))-<not<>>)-<not< // 8, 41 bytes
((join(()+<not<>>)(()+()))-<not< // 9, 32 bytes
(join(()+<not<>>)(()+( // 10, 22 bytes
(join((<not<>>+<not<>>)*(<not<>>+<not<>>))(<not<>>+<not< // 42, 56 bytes
Explanation:
()+()converts to number by default, so in its empty form returns 0<not<>>istruein Scratch, so adding it to a blank()+()gives 1- Adding two
<not<>>s yields 2 - Adding another
<not<>>makes 3 - Multiplying (3) by itself returns 4
(join(()+<not<>>)(()+()))is the concatenation of 1 and 0, or 10. Divided by (3), it gives us 5.- 6 is represented as 2*3
- 7 is 10-3, 8 is 10-2, 9 is 10-1
- See (6) part 1
- 42 is 4 joined to 2
Vyxal 3, 20 bytes
โบ
โจฅ
โบโจฅ
โฃt
โ ยฝ
โฃh
โฆแโ
โฅt
โ โน
โ
โ
O
0
โโข0+1
โโฃ0+2
โโค0+1+2
โโขโก64 tail (4)
โโขโข10/2=5
โโขโฃ64 head = 6
โโขโค256 remove tail (25) digit sum = 7
โโฃโก128 tail = 8
โโฃโข10-1 = 9
โโฃโฃ10
โโฃโคOrd(*) = 42 (I got super lucky on that one)
๐
Created with the help of Luminespire.
Nim 2, 157 bytes
Nim doesn't have implicitly imported math constants =T
len [] # 0, 6 bytes
ord on # 1, 6 bytes - `on` is alias for true
# `ord` converts to integer
NimMajor # 2, 8 bytes - Nim Major Version (2)
NimMajor.succ # 3, 13 bytes - successor is next value
cint.sizeof # 4, 11 bytes - C's int (int32), 4 bytes
cint.sizeof.succ # 5, 16 bytes
int.sizeof-NimMajor # 6, 19 bytes - Nim's int is 8 bytes on amd64
int.sizeof.pred # 7, 15 bytes - predecessor is previous value
int.sizeof # 8, 10 bytes
int.sizeof.succ # 9, 15 bytes
int.sizeof+NimMajor # 10,19 bytes
import posix
ENOMSG # 42,19 bytes - posix constant
Nim 1 and 2, 165 163 bytes
-2 bytes thanks to Adamรกtor
len []
ord on
on.ord.succ
len [on,on,on]
cint.sizeof
cint.sizeof.succ
int.sizeof.pred.pred
int.sizeof.pred
int.sizeof
int.sizeof.succ
int.sizeof.succ.succ
import posix
ENOMSG
Tcl, 311 bytes
$argc[incr i][expr [incr j]+$j][expr [incr k]+$k+$k][expr [incr l]+$l+$l+$l][expr [incr m]+$m+$m+$m+$m][expr [incr n]+$n+$n+$n+$n+$n][expr int(exp([incr o]+$o))][expr int(exp([incr p]+$p))+$p][expr ([incr q]+$q+$q)**[incr q]][expr int(exp([incr r]+$r))+$r+$r+$r][expr [set t int(exp([incr s]+$s))]**[incr s]-$t]
I had to merge all lines for TIO to get me the byte count without the line separations, here it is everything separated:
Tcl, 322 bytes
$argc
[incr i]
[expr [incr j]+$j]
[expr [incr k]+$k+$k]
[expr [incr l]+$l+$l+$l]
[expr [incr m]+$m+$m+$m+$m]
[expr [incr n]+$n+$n+$n+$n+$n]
[expr int(exp([incr o]+$o))]
[expr int(exp([incr p]+$p))+$p]
[expr ([incr q]+$q+$q)**[incr q]]
[expr int(exp([incr r]+$r))+$r+$r+$r]
[expr [set t int(exp([incr s]+$s))]**[incr s]-$t]
This is the version stripped of instructions to put it on display. To try it, on the first line just prepend puts and in the others wrap them by puts [ before and ] after.
Or else, try with the full version, on
Tcl, 382 bytes
puts $argc
puts [incr i]
puts [expr [incr j]+$j]
puts [expr [incr k]+$k+$k]
puts [expr [incr l]+$l+$l+$l]
puts [expr [incr m]+$m+$m+$m+$m]
puts [expr [incr n]+$n+$n+$n+$n+$n]
puts [expr int(exp([incr o]+$o))]
puts [expr int(exp([incr p]+$p))+$p]
puts [expr ([incr q]+$q+$q)**[incr q]]
puts [expr int(exp([incr r]+$r))+$r+$r+$r]
puts [expr [set t int(exp([incr s]+$s))]**[incr s]-$t]
Janet, 177 bytes
(+)
(*)
(inc(*))
(+(*)(*)(*))
(+(*)(*)(*)(*))
(length *redef*)
(length(type{}))
(length(type(=)))
(length(type +))
(length(type not))
(length *executable*)
(*;(map|(length(type($)))[+ =]))
Explanation
(+)
+ is the variadic add function. It returns 0 when given no arguments.
(*)
* is the variadic multiply function. It returns 1 when given no arguments.
(inc(*))
inc is a function that adds 1 to its argument.
(+(*)(*)(*))
(+(*)(*)(*)(*))
Add three or four 1s.
(length *redef*)
*redef* is a constant equal to the keyword :redef, which is 5 characters long.
(length(type{}))
The type of {} is :struct, which is 6 characters long.
(length(type(=)))
= is the variadic equality function which checks if all arguments are equal. Its return type is :boolean, which is 7 characters long.
(length(type +))
The type of + is :function, which is 8 characters long.
(length(type not))
The type of not is :cfunction (a function implemented in C), which is 9 characters long.
(length *executable*)
*executable* is a constant equal to the keyword :executable, which is 10 characters long.
(*;(map|(length(type(\$)))[+ =]))
(Ignore the backslash, StackExchangeโs Markdown is broken.) Evaluates the functions + and = with no arguments, gets the types of the results (:number and :boolean respectively) and multiplies their lengths.
Julia 1.0, 121 bytes
pi-pi
true
-~+true
floor(pi)
ceil(pi)
floor(pi+โฏ)
floor(pi+pi)
ceil(pi+pi)
floor(pi*โฏ)
floor(pi*pi)
ceil(pi*pi)
ceil((e=โฏ)e^e)
โฏ is the euler constant (3 bytes)
Pip, 29 bytes
i
o
#t
#h
#m
HVt
t-#m
t-#h
E#h
Dt
t
As+t
Explanation
i ; Variable preset to 0
o ; Variable preset to 1
#t ; Length of variable preset to 10
#h ; Length of variable preset to 100
#m ; Length of variable preset to 1000
HVt ; Half of 10
t-#m ; 10 minus length of 1000
t-#h ; 10 minus length of 100
E#h ; 2 to the power of (length of 100)
Dt ; 10 decremented
t ; 10
As+t ; ASCII code of variable preset to space character, plus 10
SAKO, 208 bytes
A=A-A
A=A-A
A=A*A
A=A-A
A=A*A+A*A
A=A-A
A=A*A+A*A+A*A
A=A-A
A=A*A+A*A
A=A*A
A=A-A
A=A*A+A*A
A=A*A+A/A
A=A-A
A=A*A+A*A
A=A*A+A
A=A-A
A=A*A+A*A
A=A*A+A+A/A
A=A-A
A=A*A+A*A
A=A*(A+A/A)
A=A-A
A=A*A+A*A
A=(A+A/A)*A
A=A-A
A=A*A+A*A
A=(A+A/A)*A+A/A
A=A-A
A=A*A+A*A
A=(A*A+A)*A+(A*A+A)
Newlines between snippets added for readability.
All I really do here is turn A by subtraction into 0, then by 0*0 into 1 and do some one-based arithmetic.
Uses KW6 as its codepage so 207,75 bytes rounded up is 208 bytes.
Bespoke, 133 bytes
from A-B-C
said I
here is
only way
this code
will reach
each number
with letters
from alphabet
that everybody
can do a commentary
and/or poem in
Each line pushes the corresponding number (0, 1, 2, 3, etc.) onto the stack.
from A-B-Cgets the heap value at address 1 (which is 0 if it is uninitialized), and pushes it onto the stack.- Each line from
said Itothat everybodywill push each number from 1 to 9 onto the stack (depending on the length of the word after the initial 4-letter word). can do a commentaryandand/or poem inpush the multi-digit numbers 10 and 42 onto the stack, like so:-
- First, a 3-letter word (meaning "push a multi-digit number").
-
- Next, a 2-letter word (meaning "this number will be 2 digits").
-
- Next, two words, where the word lengths correspond to the digits of the number. (Note that a 10-letter word corresponds to the digit 0.)
Running these snippets directly in the official interpreter with the -d flag will show these numbers after they're pushed onto the stack.
Stack: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42]
Heap: {
1: 0,
}
Vyxal, 22 bytes
โบ
โง
โบโง
โงโง
โยฝ
โงT
โโฉโน
โโฉ
โโน
โ
โEโโง
I think all of these are optimal aside from maybe 7 and 42, but I couldn't find anything shorter. 0, 1, 2, and 10 are definitely optimal at least.
# 0
โบ # 0 + 1
โง # 0 + 2
โบโง # 0 + 1 + 2
โงโง # 0 + 2 + 2
โยฝ # 10 / 2
โงT # (0 + 2) * 3
โโฉโน # 10 - 2 - 1
โโฉ # 10 - 2
โโน # 10 - 1
โ # 10
โEโโง # digitsum(2 ** 26) + 2
Python 3
len([])
len([len])
len([len,len])
len([len,len,len])
len([len,len,len,len])
len([len,len,len,len,len])
len([len,len,len,len,len,len])
len([len,len,len,len,len,len,len])
len([len,len,len,len,len,len,len,len])
len([len,len,len,len,len,len,len,len,len])
len([len,len,len,len,len,len,len,len,len,len])
len([len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len,len])
Just lists and functions. No forbidden literals!
Definitely can be golfed, but I automatically generated these, so I might golf it later.
Uiua, 37 36 bytes
โโ
โฮท
โฮท
โฯ
โฯ
โ+ฯฮท
โฯ
โฯ
โ+ฯฮท
โรฯฯ
โรฯฯ
โ+ฯโฟฯฯ
I will be curious to see if anyone has any two-byters for 0. I found a dozen three-byters. Found one!
โโ # floor of random float in [0,1)
โฮท # floor of eta (number of radians in a quarter circle)
โฮท # ceiling of eta
โฯ # floor of pi (ratio of circle's circumference to diameter)
โฯ # ceiling of pi
โ+ฯฮท # ceiling of eta plus pi
โฯ # floor of tau (ratio of circle's circumference to radius)
โฯ # ceiling of tau
โ+ฯฮท # ceiling of eta plus tau
โรฯฯ # floor of pi squared
โรฯฯ # ceiling of pi squared
โ+ฯโฟฯฯ # floor of pi to the pi plus tau
QBIC, 14 bytes
Thank you @Adรกm, for clarifying part of the rules. Brought the byecount down to 14.
a
q
r
s
t
u
v
w
x
y
z
v*w
All lower-case letters are numerical variables in QBIC, which default to 0. Exceptions are the letters q-z, which get initialised to 1-10. 42 is simply 6*7.
Actually, 32 bytes
โ
โK
โ
โฆL
โฆK
โฆLโ
โฆLฯ
โ ยฒL
โฆLโ
โฆLยฒ
kYโค
โยบโฆ+L
All full programs. Try it online!
Explanation
โisln(2)โฆispiโiseLisfloorKisceilฯisdoubleยฒissquare
For the last one:
โยบโฆ+L
โ ln(2)
ยบ convert from radian to degree (39.71440802747729)
โฆ+ + pi (42.85600068106709)
L floor
Brain-Flak, 172 143 bytes
(<>)
(())
(()())
(()()())
(()()()())
(()()()()())
((()()()){})
((()()()){}())
((()()()()){})
(((()()())){}{})
((()()()()()){})
(((((()()()){}()){})){}{})
Try it online! (copy-paste yourself)
Factor + math.unicode, 88 bytes
f ?1+
e e /
e โ
e โ
ฯ โ
ฯ e^ โ
ฯ e^ โ
e sq โ
e sq โ
ฯ sq โ
ฯ sq โ
ฯ 10^ โ
Explanation:
f ?1+ ! ?1+: increment the input by 1 or return 0 if input is f
e e / ! e (2.7182818...) divided by e
e โ ! the floor of e
e โ ! the ceiling of e
ฯ โ ! the ceiling of pi (3.14159...)
ฯ e^ โ ! the floor of e raised to the phi (1.618033...) power
ฯ e^ โ ! the ceiling of e raised to the phi power
e sq โ ! the floor of e squared
e sq โ ! the ceiling of e squared
ฯ sq โ ! the floor of pi squared
ฯ sq โ ! the ceiling of pi squared
ฯ 10^ โ ! the ceiling of 10 raised to the phi power (10^ is a function)
Deadfish / Deadfish~, Score: 62 / 56
0: o
1: io
2: iio
3: iiio
4: iiso
5: iisio
6: iisiio
7: iiisddo or {i}dddo (Deadfish~ only)
8: iiisdo or {i}ddo (Deadfish~ only)
9: iiiso or {i}do (Deadfish~ only)
10: iiisio (Deadfish) or {i}o (Deadfish~)
42: iisiisiiiiiio (Deadfish) or {iiii}iio (Deadfish~)
Amazingly, up to 9, vanilla deadfish is as efficient! I put these together because they're almost identical.
Elixir, 267 bytes
Elixir's syntax doesn't exactly lend itself to golfing, and its strong typing makes this pretty hard too.
length [] # 0
length [[]] # 1
length [[],[]] # 2
floor :math.pi # 3 (:math is technically a literal, but Elixir's atoms are neccessary to access many modules)
ceil :math.pi # 4
length [[],[],[],[],[]] # 5
floor :math.pi+:math.pi # 6
ceil :math.pi+:math.pi # 7
(ceil :math.pi+:math.pi)+length [[]] # 8
floor :math.pi*:math.pi # 9
length(Atom.to_charlist URI) # 10 (URI is an alias to Elixir.URI which is 9 characters long)
(length(Atom.to_charlist Version))*(floor :math.pi) # 42 (length of "Elixir.Version" times 3)
Pyth, 30 bytes
Z
hZ
hhZ
l`d
eCN
ePT
elG
sPT
ttT
tT
T
.ON
Breakdown: Z = Zero, T = Ten, G = alphabet.
Z // 0: Zero
hZ // 1: Zero + 1
hhZ // 2: Zero + 1 + 1
l`d // 3: length of the representation of ' '
eCN // 4: The last digit of the ascii code for " (34)
ePT // 5: Last digit of the prime factorials for 10 [2, 5]
elG // 6: Last difit of the length of the alphabet
sPT // 7: Sum of the prime factorials for 10
ttT // 8: 10 - 1 - 1
tT // 9: 10 - 1
T // 10: 10
.ON // 42: Octal value for the " character
Whispers v2, 224 bytes
> e
>> 1-1
> e
>> 1รท1
> e
>> โ1โ
> e
>> โ1โ
> ฯ
>> โ1โ
> ฯ
>> โ1โ
>> โป2
> ฯ
>> 1+1
>> โ2โ
> e
>> 1ยฒ
>> โ2โ
> e
>> 1ยฒ
>> โ2โ
> ฯ
>> 1ยฒ
>> โ2โ
> ฯ
>> 1ยฒ
>> โ2โ
> e
>> โป1
>> 1*2
>> โ3โ
Each snippet is separated by two newlines. In Whispers, digits (0123456789) only refer to their numerical value when on a nilad line i.e. if the line begins with > . These lines simply return the value represented on the line. Used in the snippets are > e and > ฯ which return \$e\$ and \$\pi\$.
How they work
0 - 10 bytes
> e
>> 1-1
Return \$e - e = 0\$
1 - 11 bytes
> e
>> 1รท1
Returns \$e \div e = 1\$
2 - 14 bytes
> e
>> โ1โ
Returns \$\lfloor e\rfloor = 2\$
3 - 14 bytes
> e
>> โ1โ
Returns \$\lceil e\rceil = 3\$
4 - 15 bytes
> ฯ
>> โ1โ
Returns \$\lceil\pi\rceil = 4\$
5 - 23 bytes
> ฯ
>> โ1โ
>> โป2
Returns \$\lceil\pi\rceil+1=5\$
6 - 22 bytes
> ฯ
>> 1+1
>> โ2โ
Returns \$\lfloor2\pi\rfloor=6\$
7 - 21 bytes
> e
>> 1ยฒ
>> โ2โ
Returns \$\lfloor e^2\rfloor = 7\$
8 - 21 bytes
> e
>> 1ยฒ
>> โ2โ
Returns \$\lceil e^2\rceil = 8\$
9 - 22 bytes
> ฯ
>> 1ยฒ
>> โ2โ
Returns \$\lfloor\pi^2\rfloor = 9\$
10 - 22 bytes
> ฯ
>> 1ยฒ
>> โ2โ
Returns \$\lceil\pi^2\rceil = 10\$
42 - 29 bytes
> e
>> โป1
>> 1*2
>> โ3โ
Returns \$\lceil e^{e+1}\rceil = 42\$
Java 8, 300 bytes
My only goal was to get every value using only java.lang.Math and integer casting. Because of that, it's probably not the best answer in terms of golf. I have fun making it, however, and that's what counts :)
If I had more time, I would have gone further and only used the constants Math.PI and Math.E.
(int)(Math.E-Math.E) // 0
(int)(Math.E/Math.E) // 1
(int)Math.E // 2
(int)Math.PI // 3
(int)(Math.E/Math.E+Math.PI) // 4
(int)(Math.E+Math.E) // 5
(int)(Math.PI+Math.PI) // 6
(int)(Math.E+Math.E+(int)Math.E) // 7
(int)(Math.E+Math.E+Math.E) // 8
(int)(Math.PI*Math.PI) // 9
(int)Math.ceil(Math.PI*Math.PI) // 10
(int)Math.ceil(Math.pow(Math.PI,Math.PI)+Math.E+Math.E) //42
Sinclair ZX81/Timex TX1000/1500 BASIC
After some discussion with Adรกm below, you have the following on the ZX81** (0 to 10 inclusive and 42), where explanations may be necessary, see the relevant note in the square brackets:
[1] .
[2] NOT .
(PI+PI)/PI
INT PI
INT PI+NOT .
INT (PI+PI)-NOT .
INT (PI+PI)
INT (PI+PI)+NOT .
INT (PI*PI+COS PI)
LEN STR$ PI
INT (PI*PI)+NOT .
[3] INT (PI**PI+PI+PI)
Notes:
- This is a short-hand of 0.0
- Not zero is 1, this is two keystrokes (so two bytes), which is shorter then PI/PI (three keystrokes)
- ** is to the power of, so it's the integer value of PI to the value of PI plus PI+PI
To see this in action, you can type it in as follows using Direct or Online mode in ZX BASIC:
PRINT .,NOT .,(PI+PI)/PI,INT PI,INT PI+NOT .,INT (PI+PI)-NOT .,INT (PI+PI),INT (PI+PI)+NOT .,INT (PI*PI+ COS PI),LEN STR$ PI,INT (PI*PI)+NOT .,INT (PI**PI+PI+PI)
Here is a more evil listing that I came up with that prints 1 to 10 inclusive (try typing it into a ZX81 emulator - actually don't):
1 PRINT LEN STR$ USR VAL (STR$ INT (EXP PI+PI)+STR$ (PI-PI)+STR$ (PI/PI+(PI/PI)))
2 PRINT (PI+PI)/PI
3 PRINT INT PI
4 PRINT INT (SGN PI+PI)
5 PRINT INT PI+(PI/PI)
6 PRINT INT (PI+PI)
7 PRINT INT ((PI+PI)+((PI/PI)))
8 PRINT INT (PI+PI+PI-SGN (PI))
9 PRINT LEN STR$ PI
10 PRINT INT (PI*PI)+PI/PI
MathGolf, 20 bytes
p # 0
รฎ # 1
โ # 2
dยฑ # 3
โปโ # 4
โยฝ # 5
Bยฝ # 6
Dยฝ # 7
โปยฝ # 8
dยฒ # 9
โ # 10
Jโ # 42
Explanation:
p # Print the top of the stack (or 0 if there is no input, nor anything on the stack)
รฎ # 1-indexed loop index (1 by default)
โ # + 2 (which becomes 0+2 by default)
dยฑ # Push -3, and then pop and push its absolute value
โปโ # Push 16, square-rooted
โยฝ # Push 10, halved
Bยฝ # Push 12, halved
Dยฝ # Push 14, halved
Fยฝ # Push 16, halved
dยฒ # Push -3, squared
โ # Push 10
Jโ # Push 21, doubled
Of course there any many alternatives for some.. i.e. 6 can alternatively be Xโ; ฯi; โx; Mยผ; Cยฝ; Nยผ; Oยผ; Pยผ; etc. (Try it online).
Husk, 42 bytes
With string and character literals forbidden as well as numbers, all Husk has to work with are sequence builtins: N (all natural numbers), รธ (empty list), and the ฤฐ family. (And functions which never get evaluated, on account of being wrapped, but that's a bit far from useful.)
Lรธ Length of the empty list.
ยฌรธ Negation of the empty list.
โฤฐp First prime. I wanted to use \. here, but even though there are no digits . is a (deliberate) corner case of numeric literal syntax and not a special constant.
โฤฐฯ First digit of pi.
โกโtN Second natural number, squared.
โฤฐ5 First power of 5. (Power sequences only exist for 2, 3, 5, and 7; the digits are arbitrary labels.)
Dโฤฐ3 First power of 3, times 2.
โฤฐ7 First power of 7.
ยฝLฮฤฐโฌ Length of the list of Euro denominations with a zero tacked on to the beginning, over 2.
โกโฤฐฯ First digit of pi, squared.
โฤฐโฐ First power of 10.
DโDโฤฐโฐ First power of 10, times 2, plus 1, times 2.
Japt, 22 bytes
0: T T == 0
1: v Implicit input 0; Number.v gives 1 if it's even, 0 otherwise
2: y Number.y(other) gives GCD of two numbers; `other` defaults to 2
3: D-A A == 10, D == 13; 13-10
4: Gq G == 16; 16.sqrt()
5: Az Number.z(other) gives this/other rounded towards 0; `other` defaults to 2
6: Cz C == 12
7: Ez E == 14
8: Iq I == 64
9: Aร ร is a shortcut for `-1`
10: A Obviously.
42: H+A H == 32; 32+10
Excel VBA, 59 bytes
Enums from the Excel object available to VBA. n is said to be an uninitialized variable and thus holds the default value of 0 as a Variant.
These snippets may be called to the VBE immediate window by prepending with ?. e.g. ?xlOr.
Further information on each response is commented to the right
00: -n '' 2 bytes; Uninitialized var `n` defaults to `0`
01: n^n '' 3 bytes; 0^0=1
02: xlOr '' 4 bytes; Excel.XlAutoFilterOperator.xlOr
03: xlSet '' 5 bytes; Excel.XlCubeFieldType.xlSet
04: xlWKS '' 5 bytes; Excel.XlFileFormat.xlWKS
05: xlDXF '' 5 bytes; Excel.XlPictureConvertorType.xlDXF
06: xlCSV '' 5 bytes; Excel.XlFileFormat.xlCSV
07: xlCGM '' 5 bytes; Excel.XlPictureConvertorType.xlCGM
08: xlEPS '' 5 bytes; Excel.XlPictureConvertorType.xlEPS
09: xlTIF '' 5 bytes; Excel.XlPictureConvertorType.xlTIF
10: xlPCX '' 5 bytes; Excel.XlPictureConvertorType.xlPCX
42: xlWJ3+xlOr '' 10 bytes; Excel.XlFileFormat.xlWJ3+Excel.XlAutoFilterOperator.xlOr
Processing, 65 44 bytes
X
Y
Z
HSB
Z*Z
LINES
HSB*Z
TAB-Z
MITER
X+TAB
-~TAB
BOX+Y
Explanation
Using the hint from the question, I decided to use Processing constants to produce these numbers. These constants contain a numerical value. So to gather them, I used PConstants.java.
Here is the list of all the constants I used:
X == 0
Y == 1
Z == 2
HSB == 3
LINES == 5
MITER == 8
TAB == 9 (char)
BOX == 41
After this, all that was left for me to do is to choose the combinations of these constants that produce the numbers 1 to 10 and 42. Finally, I ended up with these:
println(X);//0
println(Y);//1
println(Z);//2
println(HSB);//3
println(Z*Z);//2 * 2 = 4
println(LINES);//5
println(HSB*Z);//3 * 2 = 6
println(TAB-Z);//9 - 2 = 7
println(MITER);//8
println(X+TAB);//0 + 9 = 9
println(-~TAB);//-~9 = 10
println(BOX+Y);//41 + 1 = 42
Several notes:
TAB has a char value of 9, meaning that if I print TAB, I print a literal tab. So to convert it to an int, I just add 0 to it.
And that's it!
Edit
I discovered PConstants.java. It appears to contain all of the constants that exist in Processing. All that research I did is on the Processing Reference is not needed anymore. Time to cut down on the bytes :)
Lua 5.3, 146 bytes
Uses a lot of length operators. Version probably doesn't matter but it is dependent on the value of _VERSION so I might as well include it for clarity.
0. #{}
1. #{_G}
2. #{_G}+#{_G}
3. #type(x)
4. #type{}-#{_G}
5. #type{}
6. #type{}+#{_G}
7. #_VERSION
8. #type(load)
9. #type(load)+#{_G}
10. #_VERSION+#type(x)
42. - -(#type{}-#{_G}..#{_G}+#{_G})
Annotated with explainations:
0. #{} -- {} is an empty table, # is the length operator, length of empty table is 0.
1. #{_G} -- {_G} is a table containing the global environment (itself a table), so there is one item.
2. #{_G}+#{_G} -- 1+1
3. #type(x) -- x is not set and so defaults to nil, type(nil) returns the string "nil", length of "nil" is 3.
4. #type{}-#{_G} -- 5-1
5. #type{} -- type of table is "table", length of "table" is 5, brackets not required when only argument is a table literal.
6. #type{}+#{_G} -- 5+1
7. #_VERSION -- _VERSION contains the current version as a string ("Lua 5.3"), of length 7.
8. #type(load) -- type of 'load' is "function", length of "function" is 8.
9. #type(load)+#{_G} -- 8+1
10. #_VERSION+#type(x) -- 7+3
42. - -(#type{}-#{_G}..#{_G}+#{_G}) -- concatenation operator implicitly converts numerical operands to strings, resulting in "4".."2"=="42". Double negation converts it to a number.
SmileBASIC, 73 71 bytes
#NO 'unknown use (maybe dialog box results?)
#UP 'd-pad up
#CHKZ 'used in SPCHK and BGCHK to get the z coordinate
#TRED 'text color red
#LEFT 'd-pad left
#BQLSF 'biquad low shelf filter
#BQHSF 'biquad high shelf filter
#BQPEQ 'biquad peaking equalizer
#CHKI 'used in SPCHK to check definition number
#TBLUE 'text color blue
#TPURPLE 'text color purple
#BQHSF*#BQPEQ '42
Ruby, 149 147 bytes
$.
-~$.
-~-~$.
-~-~-~$.
-~-~-~-~$.
-~-~-~-~-~$.
-~-~-~$.>>~$.
-~-~-~-~-~-~-~$.
-~$.>>~-~-~$.
-~$.>>~-~-~$.|-~$.
-~-~-~-~-~$.>>~$.
-~-~-~-~-~$.>>~-~-~$.|-~-~$.
Explanation:
$.is the number of the last line read from the current input file. Since we are not reading any file, this is initialized with 0.
1 through 5 are just the previous number +1, then I can use shifts for multiplication (negative right shift saves 1 byte) and or for addition (can't use +/- because of priority).
So, for example, 42 is 5>>-3|2
PHP, 38 37 bytes
Note: uses IBM-850 encoding.
+_ #0
+~โฌ #1
+~โ #2
+~โ #3
+~โฆ #4
+~โฉ #5
+~โ #6
+~โ #7
+~ร #8
+~รฃ #9
+~โฌยค #10
+~โฆโ #42
Explanation
Undefined constants in PHP have their name as default value. The resulting string is then negated to result in "0", "42" etc. Finally, it's converted to integer using the leading +.
Tweaks
- Saved a byte by exploiting the fact that converting any string results in
0when converted toint, except when it matches/^[0-9.]+/
05AB1E, 40 38 24 bytes
ยพ
X
Y
Xร
Yยท
T;
T;>
T;ร
Tร
T<
T
ลพwT+
- Push counter_variable
- Push 1
- Push 2
- Push 1+2
- Push 2*2
- Push 10/2
- Push (10/2)+1
- Push (10/2)+2
- Push 10-2
- Push 10-1
- Push 10
- Push 32, 10, add
Funciton, 1222 bytes
Apart from numeric literals, there are two ways I can produce a value (any value at all) in Funciton: stdin and lambda expressions. Stdin is a single box while a full lambda expression requires more syntax, so Iโm going with stdin. However, while stdin could be anything, all of the following work regardless of what input is provided.
All of the library functions used here existed before the challenge was posted.
0 (40 bytes in UTF-16)
โโโโ
โโโคโโผโฌโ
โโโโโโโ
This uses the raw syntax for less-than. A value is never less than itself, so the result of this is 0.
1 (52 bytes in UTF-16)
โโโโโโโโ
โโโคโโโคษโ
โโโโโโโโ
โ returns a lazy sequence containing a single element and ษ counts the number of elements. (The lazy sequence is lazy enough that this snippet doesnโt actually evaluate stdin at all!)
2 (70 bytes in UTF-16)
โโโโโโโโโโโ
โโโคโโโคสโโคษโ
โโโโโโโโโโโ
= 2ยน. ส generates all subsequences of a sequence, and thus turns a sequence of n elements into one with 2โฟ.
3 (88 bytes in UTF-16)
โโโโโโโโโโโโโโ
โโโคโโโคสโโคษโโคโฏโ
โโโโโโโโโโโโโโ
= 2 + 1. โฏ increments a value by 1.
4 (88 bytes in UTF-16)
โโโโโโโโโโโโโโ
โโโคโโโคสโโคสโโคษโ
โโโโโโโโโโโโโโ
= 2ยฒ.
5 (106 bytes in UTF-16)
โโโโโโโโโโโโโโโโโ
โโโคโโโคสโโคสโโคษโโคโฏโ
โโโโโโโโโโโโโโโโโ
= 4 + 1.
6 (106 bytes in UTF-16)
โโโโโโโโโโโโโโโโโ
โโโคโโโคสโโคษโโคโฏโโค!โ
โโโโโโโโโโโโโโโโโ
= 3 factorial.
7 (110 bytes in UTF-16)
โโโโโโโโโโโโโโโโ
โโโโโโคษโโคสโโคโโโขโ
โโคAโโโโโโโโโโโโโ
โโคโ
= A(2, 2) (Ackermann function).
8 (118 bytes in UTF-16)
โโโโโโโโโโโโโโโโโ
โโโโโโโคษโโคสโโคโโโขโ
โโค<<โโโโโโโโโโโโโ
โโคโโ
= 2 << 2 (shift-left).
9 (128 bytes in UTF-16)
โโโโโโโโโโโโโโโโโโโ
โโโโโโคโฏโโคษโโคสโโคโโโขโ
โโครโโโโโโโโโโโโโโโโ
โโคโ
= 3 ร 3.
10 (146 bytes in UTF-16)
โโโโโโโโโโโโโโโโโโโโโโ
โโโโโโคโฏโโคษโโคสโโคสโโคโโโขโ
โโค+โโโโโโโโโโโโโโโโโโโ
โโคโ
= 5 + 5.
42 (170 bytes in UTF-16)
โโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโค!โโคโฏโโคษโโคสโโคโโโขโ
โโคโฏโโครโโโโโโโโโโโโโโโโโโโ
โโโโโคโ
= 6 ร (6 + 1).
Racket 205 bytes
(- pi pi)
(/ pi pi)
(/(+ pi pi)pi)
(floor pi)
(ceiling pi)
(sub1(floor(+ pi pi)))
(floor(+ pi pi))
(ceiling(+ pi pi))
(floor(sub1(* pi pi)))
(floor(* pi pi))
(ceiling(* pi pi))
(floor(+ pi pi(expt pi pi)))
Output:
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
42.0
Haskell, 212 210 198 196 190 187 134 bytes
Edit: After reading in the FAQ that using pi is allowed, throwing everything away and doing it all using pionly saves a lot of bytes.
pi-pi -- 0.0, 5 bytes
pi/pi -- 1.0, 5 bytes
succ$pi/pi -- 2.0, 10 bytes
floor pi -- 3, 8 bytes
ceiling pi -- 4, 10 bytes
succ.ceiling$pi -- 5, 15 bytes
floor$pi+pi -- 6, 11 bytes
ceiling$pi+pi -- 7, 13 bytes
pred.floor$pi*pi -- 8, 16 bytes
floor$pi*pi -- 9, 11 bytes
round$pi*pi -- 10, 11 bytes
floor$pi**pi+pi+pi -- 42, 18 bytes
However, I still like the old approach more as using a number to generate other numbers feels a bit like cheating.
sum[] -- 0, 5 bytes
length[LT] -- 1, 10 bytes
fromEnum GT -- 2, 11 bytes
length[LT ..] -- 3, 13 bytes
length$show[()] -- 4, 15 bytes
length.show$False -- 5, 17 bytes
length$show[True] -- 6, 17 bytes
length.show$Left() -- 7, 18 bytes
length.show$Right() -- 8, 19 bytes
length$show[Just[]] -- 9, 19 bytes
length$show[LT ..] -- 10, 18 bytes
fromEnum.succ.last$show() -- 42, 25 bytes
LT,EQ and GT are the values of the Ordering Type. As Ordering is an instance of Enum, fromEnum GT yields 2 and [LT ..] creates the list [LT,EQ,GT]. show converts all instances of the Show type class to strings.
Bonus:
42 in 42 bytes: length.show$Just$[LT ..]>>[EQ,GT]>>[GT,LT]
How long is nothing? length Nothing
Perl 5, 86 75 71 66 bytes
All ^Fs are literal control characters (0x06 in ASCII), and hence a single byte.
$[ # array start index, defaults to 0 2
!$[ # !0 is 1 3
$^F # max sys file descriptor number, 2 on all sane systems 2
++$^F # 2 + 1 4
~-$] # 5 - 1 4
int$] # $] is Perl version, int truncates 5
length$~ # 1 + 5 8
~~exp$^F # floor(e^2) 7
$^F<<$^F # 2 bitshift-right 2 6
-!$[+ord$/ # -1 + 10 10
ord$/ # input record separator, newline by default, ord gets ASCII val 5
ord($"^$/) # 32 + 10 10
Thanks to msh210 for saving 11 bytes and Dom Hastings for 9 bytes!
Haskell, 133 bytes
Pi-based, three floating point answers with the rest being integers:
0: (5) pi-pi
1: (5) pi/pi
2: (10) (pi+pi)/pi
3: (8) round pi
4: (10) ceiling pi
5: (15) succ.ceiling$pi
6: (11) floor$pi+pi
7: (13) ceiling$pi+pi
8: (16) floor$cosh pi-pi
9: (11) floor$pi*pi
10: (11) round$pi*pi
42: (18) floor$pi**pi+pi+pi
Mouse-2002, 27 26 17 14 bytes
The first snippets push 0-10, and ZR+ pushes 25 then 17 and 25 17 + 42 = is 1.
A
B
C
D
E
F
G
H
I
J
K
ZR+
Jelly, 26 bytes (non-competing)
00:
01: โ
02: โโ
03: โโโ
04: โโแธค
05: โตH
06: โตHโ
07: โดHโ
08: โดH
09: โตโ
10: โต
42: โดแธค+โต
Try it online! (paste each one of the snippets in the 'Code' field.)
DC, 35 bytes
K
KZ
IZ
Iv
EI-
FI-
IZd*
IIZ/
Ivd+
IIv-
IIZ-
IKZ-
I
EdE++
To test the snippets append a f to print the stack and pass that string to dc:
$ echo 'EdE++f' | dc
42
BASH, 318 bytes
0 to 3 are exit code, other ones are stored in A
bytes count is split as follow :2-5-5-26-23-32-26-38-26-33-32-70
#0
ls
#1
cd \\
#2
ls \\
#3
cd \\
A=$?
A=$(($A+$A+$A))
#4
ls \\
A=$?
A=$(($A*$A))
#5
cd \\
A=$?
A=$(($A+$A+$A+$A+$A))
#6
ls \\
A=$?
A=$(($A+$A+$A))
#7
cd \\
A=$?
A=$(($A+$A+$A+$A+$A+$A+$A))
#8
ls \\
A=$?
A=$(($A*$A*$A))
#9
A=$?
A=$(($A+$A+$A))
#10
ls \\
A=$?
A=$(($A+$A+$A+$A+$A))
#42
@
A=$?
cd \\
B=$?
cd \\
C=$?
C=$(($C+$C+$C))
B=$(($A-$B))
A=$(($B/$C))
7 is more than probably golfable a bit more, as is 42
Perl6 (117 112) no state
e-e
e/e
e.floor
e.round
pi.ceiling
floor e+e
tau.floor
tau.ceiling
floor pi*e
floor pi*pi
round pi*pi
tau.floor*tau.ceiling
Hexagony, 13 bytes
1 2 3 4 5 6 7 8 9 10 42
In Hexagony, 0 through 9 are functions that multiply the current memory by 10, and then add the number represented by the function name. Therefore, the first snippet is empty as memories start off as 0.
For example, if the current memory is 65, executing the function 3 will make the current memory 653.
(To downvoters: downvote all you want; I am ready.)
C, 78 bytes
Quite a handful of undefined behaviours.
The implementation is gcc (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2), using this online C sandbox.
a-a //1-1
a //1
a+a //1+1
a+a+a //1+1+1
++a*a //2*2
++a+a++ //3+2
++a*a++ //3*2
a+++a+a+a //1+2+2+2
++a<<a //2<<2
++a*++a //3*3
a+++a*++a //1+3*3
(a=++a*a++)*a+a //(a=3*2)*a+a
a defaults to 1 being the first argument of main.
Boilerplate example for the last one:
#include <stdio.h>
int main(int a)
{
printf("%d\n",(a=++a*a++)*a+a);
return 0;
}
without undefined behaviors, 88 bytes
a-a //1-1
a //1
a+a //1+1
a+a+a //1+1+1
a<<a+a //1<<2
a<<a+a|a //(1<<2)|1
a+a+a<<a //3<<1
a+a+a<<a|a //(3<<1)|1
a+a<<a+a //2<<2
a+a<<a+a|a //(2<<2)|1
a++;a<<a|a //(2<<2)|2
a=a+a+a<<a;a*a+a //a=3<<1;a*a+a
J, 46 43 42 bytes
Thanks to Nแดฎแถป for the help and exploration!
%_ NB. Inverse of infinity
_. NB. Indeterminate value, evaluates to 1
2:_
3:_
4:_
5:_
6:_
7:_
8:_
9:_
+~5:_ NB. verb magic
(7:*6:)_ NB. 7 * 6
Here are some other programs:
(number): (representation)
1: *_ NB. signum of infinity same bytes
1: #a: NB. The tally of the Ace/Empty box +1 byte
1: 1:_ NB. The constant function with infinity; +1 byte
2: #_`_ NB. The tally of infinity gerund-ed with itself +1 byte
2: #_,_ NB. (same) +1 byte
2: #_;_ NB. (same) +1 byte
42: (*:+])6:_ NB. verb magic / 6 squared plus 6 +1 byte
42: +:<.o.7:_ NB. double floor pi times 7 +1 byte
42: <.(#a.)%6:_ NB. Tally of alphabet (256) divided by 6 (6:_) floored (<.); +3 bytes
42: a+*~(a=:6:_) NB. 6 squared plus 6. +4 bytes
42: (a=:6:_)+:*a NB. 6 squared plus 6. +4 bytes
42: #C.>.%:^@^2:_ NB. I'm not entirely sure how this works +5 bytes
Ruby, 194 bytes
[]<=>[]
[[]].size
[[],[]].size
Dir.name.size
Hash.name.size
Float.name.size
Method.name.size
Integer.name.size
NilClass.name.size
TrueClass.name.size
FalseClass.name.size
Integer.name.size*Method.name.size
DUP, 68 bytes
[
[
[
[)]!
[ )]!
[ )]!
[)~_]!
[ )~_]!
[ )~_]!
[ )~_]!
[)$+]!
[ )$+~_$+]!
There are a LOT of ways to do this, but I'm abusing the return stack for this one.
Explanation
To fully figure this out, you need to understand DUP's behavior regarding lambdas. Instead of pushing the lambda itself to the stack, it actually pushes the current IP to the stack when the lambda is detected. That can explain the first 3 snippets, which involve lambdas.
The next snippets use the return stack. When ! is executed, the current IP is pushed to the return stack, and the top of the stack is set as the new IP to start lambda execution. ) pops a number from the return stack onto the data stack.
That's pretty much enough to explain the rest of the snippets. If you still don't get it, keep in mind that the Step button is quite handy!
Jolf, 26 bytes
<empty>
lฮญ
lq
mfฯ
Uฮฌ
ยฝt
mfฯ
mฮCt
wwt
wt
t
mQ
Okay, so I have a 42-builtin. I'm obsessed with that number. Also for forty-two, lm,t: the length of the integer partitions of ten.
Explanations
The empty program is a truth machine, and, since given no input, just output's a zero.
lฮญ is the length of a tab, i.e., 1.
lq is the length of the source code, i.e., 2.
mfฯ is the floor of pi, i.e., 3.
Uฮฌ is the square root of 16, i.e., 4.
ยฝt is half ten, i.e., 5.
mfฯ is the floor of tau (i.e. twice pi), i.e., 6
mฮCt is the length of the collatz sequence beginning with ten, i.e. 7.
wwt is 10-1-1, i.e., 8.
wt is 10-1, i.e., 9.
t is 10.
mQ is the builtin for 42.
Alternate solution
Except for 0 and 10, a solution with @<char with charcode value of N> would be golfier solution for N, however, even though it doesn't use any literals (it actually reads the source code's next character), it isn't in the spirit of the challenge. This would tally 20 bytes.
Cardinal, 50 bytes
Instructions, with alternatives if they have the same lengths:
0: IPs are initialized to 0, otherwise, use instruction 0
1: +
2: ++
3: +++
4: ++++ or ++=* or ++=t
5: +++++ or ++=t+ or ++=*+
6: +++=* or ++=**
7: +++=*+ or ++=tt-
8: ++=tt
9: +++=t
10: ++=tt* or +++=t+
42: +++=*=t*
Explanation:
IPs in Cardinal carry length 2 stacks around. The topmost value is called active, the bottom value is called passive. Both can switch roles.
+ increment active value
- decrement active value
* addition : active=active+passive
t multiplication: active=active*passive
= set passive = active value
Staq, 60 bytes
& 0
&i 1
&ii 2
&iii 3
&iiq 4
&iiqi 5
&iiqii 6
&iiiqdd 7
&iiiqd 8
&iiiq 9
&iiiqi 10
&iiqii&+qX+ 42
Instructions:
& push 0 on top of stack
i increment top stack value
d decrement top stack value
q square top stack value
+ add top and 2nd stack values, put sum on top of stack
X delete 2nd stack value
beeswax, 50 46 bytes
(62 57 bytes, if IPs are not initialized)
Explanation of instructions:
P increment top lstack value
M decrement top lstack value
z all lstack values = 0
F all lstack values = top
G get value from absolute(row,column) = lstack(2nd,3rd) value.
@ flip 1st and 3rd lstack values
. top=top*2nd value
+ top=top+2nd value
! bitwise NOT
(bel) ASCII control character 7, not printable
Instructions for number creation without using numbers, with multiple examples, if the byte lengths are the same. Prepend z if the bee is not in an initialized state:
initialized to 0 not initialized to 0
prepend z
no instruction [0,0,0]โข z
P [0,0,1]โข zP
PP [0,0,2]โข zPP
PPP [0,0,3]โข zPPP
PPF. or PPPP or PPF+ [0,0,4]โข zPPF.
PPF.P or PPF+P or PPPPP [0,0,5]โข zPPF.P
PPPF+ or PPF++ or PPFP. [0,0,6]โข zPPPF+
PPPF+P or PPF..M [0,0,7]โข zPPF..M
(bel)*1FG [0,0,7]โข โ this would make โ7โ one byte shorter
PPF.. [0,0,8]โข zPPF..
PPPF. [0,0,9]โข zPPPF.
PPPF.P [0,0,10]โข zPPPF.P
*PFG [0,0,42]โข *PFG (in this configuration the IP is always initialized)
You can clone my beeswax GitHub repository here.
JavaScript, 144 141 140 138 132 125 123 bytes
With help from @edc65, @Sjoerd Job Postmus, @DocMax, @usandfriends, @Charlie Wynn and @Mwr247!
result.textContent = [
+[] ,// 0 (3 bytes)
-~[] ,// 1 (4 bytes)
-~-~[] ,// 2 (6 bytes)
-~-~-~[] ,// 3 (8 bytes)
-~Math.PI ,// 4 (9 bytes)
-~-~Math.PI ,// 5 (11 bytes)
-~-~-~Math.PI ,// 6 (13 bytes)
Date.length ,// 7 (11 bytes)
(a=-~-~[])<<a ,// 8 (13 bytes) = (2 << 2)
(a=~Math.E)*a ,// 9 (13 bytes) = (-3 * -3)
(a=-~-~[])<<a|a ,// 10 (15 bytes) = ((2 << 2) | 2)
(a=Date.length)*--a // 42 (19 bytes) = (7 * 6)
];
<pre id="result"></pre>
PowerShell, 147 bytes
These use + to implicitly cast things to integers. The later numbers use Enums from the .Net Framework unerpinnings of PowerShell which happen to have the right values.
+$a #0, 3 bytes (unset vars are $null, +$null == 0)
+$? #1, 3 bytes (bool previous result, default $true, +$true == 1)
$?+$? #2, 5 bytes (same as #1, twice)
$?+$?+$? #3, 8 bytes (beats [Int][Math]::E)
$?+$?-shl$? #4, 11 bytes (-shl is shift-left)
$?+$?+$?+$?+$? #5, 14 bytes
$?+$?+$?-shl$? #6, 14 bytes (enum value, + casts to integer)
+[TypeCode]::Int16 #7, 18 bytes
$?+$?-shl$?+$? #8, 14 bytes
+[consolekey]::tab #9, 18 bytes
+[TypeCode]::UInt32 #10, 19 bytes
+[consolekey]::Print #42, 20 bytes
#Total: 147 bytes
-~-~-~used in JavaScript, C# and PHP answers would be- -bnot - -bnot - -bnotin PowerShell.x^yexponentiation used in Perl answers, orx**yin Python or JavaScript ES7, would be[Math]::Pow($x,$y)constants e and Pi are the character-heavy
[Math]::Eand[Math]::PI
Hoon, 89 bytes
`@`&
`@`|
+(|)
+:!=(+)
+:!=(-<)
+:!=(->)
+:!=(+<)
+:!=(+>)
+:!=(-<-)
+:!=(-<+)
+:!=(->-)
+:!=(->->-)
0 is just "yes" (0) casted to an atom
1 is just "no" (1) casted to an atom
2 is incremented "no" - .+ automatically casts to an atom, so no need for @
3 - 42 are the fun ones: It's using the != rune, which compiles an arbitrary Hoon expression to Nock. In this case, it's compiling axis navigation syntax into the Nock expression [0 axis], which I then take the tail of with +:expr.
In Hoon, all variable accesses are actually just indexing into a binary tree, and it allows you to index manually as well. The syntax is alternating sets of -/+ and </>, each one being head/tails for the current node. I also use +axis, which is a bit shorter for 8, 9, and 42.
R, 100 bytes
Copied the solutions for 6 and 7 from @MiloChen here.
+F # | 0 | 2 bytes
+T # | 1 | 2 bytes
T+T # | 2 | 3 bytes
T+T+T # | 3 | 5 bytes
T+T+T+T # | 4 | 7 bytes
T+T+T+T+T # | 5 | 9 bytes
nrow(BOD) # | 6 | 9 bytes
cars$s[pi] # | 7 | 10 bytes
cars$s[pi]+T # | 8 | 12 bytes
(pi*pi)%/%T # | 9 | 11 bytes
(pi*pi)%/%T+T # | 10 | 13 bytes
(pi^pi+pi+pi)%/%T # | 42 | 17 bytes
# | total | 100 bytes
This saves some bytes compared to the 123 and 165 solutions.
MS Excel formulas, 163 151 150 143 bytes
Not exactly a programming language, but here it goes...
0: -Z9 (03 bytes)
1: N(TRUE) (07 bytes)
2: TYPE(T(Z9)) (11 bytes)
3: TRUNC(PI()) (11 bytes)
4: TYPE(TRUE) (10 bytes)
5: ODD(PI()) (09 bytes)
6: FACT(PI()) (10 bytes)
7: ODD(PI()+PI()) (14 bytes)
8: EVEN(PI()+PI()) (15 bytes)
9: TRUNC(PI()*PI()) (16 bytes)
10: EVEN(PI()*PI()) (15 bytes)
42: EVEN(CODE(-PI())-PI()) (22 bytes)
PI() is used in most cases as it is the shorter way (that I am aware of) to introduce a numeric value without using a number or string literal. N converts various things (incl. booleans) to numbers, and T converts various things to text. TYPE returns 2 for a text argument and 4 for a boolean argument. TRUNC discards fractional part (i.e. rounds positive numbers down), EVEN rounds up to the next even number, and ODD rounds up to the next odd number. CODE(-PI()) is the ASCII code of the first character of the conversion to text of -ฯ, i.e. 45 (for "-").
EDIT: Removed equal signs from the byte count (-12!) - as pointed out by Nแดฎแถป in the comments, they are not supposed to be included.
EDIT 2: Assuming the rest of the worksheet is empty, it is possible to use a reference to an empty cell as zero (again, suggested by Nแดฎแถป) provided that we include a minus sign (or use it in other numeric expression) to resolve type ambiguity.
Jelly, 31
<blank>
โ
โโ
โโโ
โโยฒ
โโยฒโ
โโโแธค
โดHโ
โดH
โโโยฒ
โต
โดแธคโต+
Explanation
0: Outputs 0 by default
- Increment
- Increment twice
- Increment thrice
- Increment twice and square
- Increment twice, square, and increment
- Increment thrice and double
- Halve sixteen and decrement
- Halve sixteen
- Increment thrice and square
- Ten
42: Double sixteen and add ten
C#, no usings, 234 bytes
new int() // 0
-~new int() // 1
-~-~new int() // 2
-~-~-~new int() // 3
-~-~-~-~new int() // 4
-~-~-~-~-~new int() // 5
-~-~-~-~-~-~new int() // 6
-~-~-~-~-~-~-~new int() // 7
-~-~-~-~-~-~-~-~new int() // 8
(int)System.ConsoleKey.Tab // 9
(int)System.TypeCode.UInt32 // 10
(int)System.ConsoleKey.Print // 42
This is much more boring than I initially thought it was going to be. I had pretty varied ideas, such as new[]{true}.Length and true.GetHashCode() and typeof(int).Name.Length and uint.MinValue etc., but new int() beat them all.
Visual Basic for Applications, no named constants, 134 bytes
That's tougher:
-x '=0 (2 bytes)
x^x '=1 (3 bytes)
x^x+x^x '=2 (7 bytes)
x^x+x^x+x^x '=3 (11 bytes)
Len(Year(x)) '=4 (12 bytes)
Len(Year(x)&-x) '=5 (15 bytes)
Day(x)Mod Month(x) '=6 (18 bytes)
Len(Time())-x^x '=7 (15 bytes)
Len(Time()) '=8 (11 bytes)
Len(Time()&-x) '=9 (14 bytes)
Len(Date()) '=10 (11 bytes)
Day(x)+Month(x) '=42 (15 bytes)
Total = 134 bytes. Again, - and ^ force undeclared variables (Variants) to be treated as numeric, and in VBA 0^0 evals to 1.
The concatenation operator force numbers to string form, so -x is 0 and &-x is & "0".
For Day, Month and Year functions, zero corresponds to december 31, 1899.
I also used the fact that (at least for most locales), VBA date strings have 10 characters and time strings have eight...
Thanks! This was a funny challenge.
Dyalog APL, 59 52 bytes
-7 bytes by @NBZ
I wasn't about to let one of @NBZ's questions go without an APL answer!
โดโฌ 0
โIO 1
โดโSD 2
โWX 3
โดโAI 4
โโโPW 5
โโโFR 6
โดโTS 7
+โจโดโAI 8
โโโโIO 9; floor(pi^2 times โIO)
โดโD 10
โโฝโโ*โโข# 42
In the last snippet, by NBZ, โข# equals 1. ceil(e^(pi*1)) is calculated as 24, whose digits are then swapped.
Constants used:
โฌ, is the empty numeric one-dimensional vector. Therefore, its shapeโดโฌis 0.#is a special vector of length 1.โIO(index origin) starts at 1.โAV, the character set, is of length 256.โPW, the print width, is 79 characters.โWX, window expose (whatever that is) is 3.โFR, the float representation, is 645. I have no idea what this is either.โD, "digits", is '0123456789'.โTS, timestamp, has seven elements: Year, month, day, hr, min, sec, ms.โSD, screen dimensions, has two elements: width and height.โAI, account info, has four elements. I don't know what they are.
Haskell, 295 bytes
0: length[]
1: length[()]
2: length[(),()]
3: length[(),(),()]
4: length[(),(),(),()]
5: length[(),(),(),(),()]
6: length[(),(),(),(),(),()]
7: length[(),(),(),(),(),(),()]
8: length[(),(),(),(),(),(),(),()]
9: length[(),(),()]*length[(),(),()]
10: length[(),()]*length[(),(),(),(),()]
42: length[(),(),(),(),(),()]*length[(),(),(),(),(),(),()]
Perl 6, 84 81 bytes
+$ # 0
++$ # 1
-+^++$ # 2
-+^e # 3
-+^ฯ # 4
1+-+^ฯ # 5
floor ฯ # 6
-+^ฯ # 7
floor e*ฯ # 8
floor ฯ*ฯ # 9
-+^(ฯ+e) # 10
-+^(e**e*e) # 42
Constants used
> e
2.71828182845905
> ฯ
3.14159265358979
> ฯ
6.28318530717959
An attempt at some explanation
#0: $ is an anonymous state variable, the + coerces it to a number, and
by default its value is 0
#1: ++$ increases the state var by 1, giving us 1
#2: +^ as a prefix is the Integer bitwise negation operator, use that with ++$ (1) and we get -2, use - to negate it and give 2
#3: Use +^ with e, which is coerced to Int, giving -3 which then gets negated with -
#4: Same as #3 but with ฯ
#5: Same as #4 but add 1
I think the rest are easy to follow with the above bits explained.
Visual Basic for Applications, 68 bytes
VBA has a lot of builtin constants and public enums. I opted not to use any external or MS Office-specific library - only base VBA:
-x '=0 (2 bytes)
x^x '=1 (3 bytes)
vbGet '=2 (5 bytes)
vbLong '=3 (6 bytes)
vbLet '=4 (5 bytes)
vbDouble '=5 (8 bytes)
vbYes '=6 (5 bytes)
vbNo '=7 (4 bytes)
vbSet '=8 (5 bytes)
vbObject '=9 (8 bytes)
vbError '=10 (7 bytes)
vbKeyPrint '=42 (10 bytes)
Total = 68 bytes. Notice that by default, undeclared variables (such as x above) are all set to blank Variants, that may be interpreted, depending on context, as 0 or as an empty string. However, both operators - and ^ force it to be numeric. Also, in VBA, 0^0 is evaluated to 1 (instead of generating an error as one might expect). I'll also post an answer without constants.
80386 machine code, 73 bytes
Hexdump:
33 c0
33 c0 40
33 c0 40 40
33 c0 40 40 40
33 c0 40 40 40 40
33 c0 40 8d 04 80
33 c0 40 8d 04 80 40
33 c0 40 8d 04 80 40 40
33 c0 40 8d 04 c0 48
33 c0 40 8d 04 c0
33 c0 40 8d 04 c0 40
33 c0 40 8d 04 c0 8d 04 80 48 48 48
The snippets calculate the required value in the eax register, suitable as a return value from a function.
I used various combinations of the following instructions:
xor eax, eax (33 c0) eax = 0
inc eax (40) eax = eax + 1
dec eax (48) eax = eax - 1
lea eax, [eax+eax*4] (8d 04 80) eax = eax * 5
lea eax, [eax+eax*8] (8d 04 c0) eax = eax * 9
The numbers here are too small to use all the possibilities of the instruction set - the only noteworthy thing here is the easy multiplication by 5 and 9. For example, here is a 13-byte snippet whose result is 2016:
33 c0 xor eax, eax eax = 0
40 inc eax eax = 1
8d 0c c0 lea ecx, [eax+eax*8] ecx = 9
8d 04 89 lea eax, [ecx+ecx*4] eax = 45
f7 e0 mul eax eax = 2025
2b c1 sub eax, ecx eax = 2016
R, 166 165 bytes
I made a PI based answer
pi-pi # 0
pi/pi # 1
(pi+pi)/pi # 2
floor(pi) # 3
ceiling(pi) # 4
ceiling(pi)+pi/pi # 5
floor(pi+pi) # 6
ceiling(pi+pi) # 7
floor(pi*pi)-pi/pi # 8
floor(pi*pi) # 9
ceiling(pi*pi) # 10
ceiling(pi^pi+pi+sqrt(pi)) # 42
Math++, 92 bytes total
0 (1 bytes): a
1 (2 bytes):!a
2 (3 bytes):_$e
3 (4 bytes): _$pi
4 (7 bytes): _$e+_$e
5 (8 bytes): _($e+$e)
6 (9 bytes): _$pi+_$pi
7 (8 bytes): _($e*$e)
8 (9 bytes): _($e*$pi)
9 (10 bytes): _($pi*$pi)
10 (12 bytes): _$e*_($e+$e)
42 (19 bytes): _($pi+$pi)*_($e*$e)
><>, 86 bytes
- 0:
ln; - 1:
lln; - 2:
llln; - 3:
lll+n; - 4:
lll:+n; - 5:
llll+n; - 6:
llll++n;orllll:+n; - 7:
lllll+n; - 8:
lllll:+n; - 9:
lllll++n;orllllll+n; - 10:
llll+:+n;orlll:l+*n; - 42:
llll*ll+*n;
Relies on stack size to get its literals.
dc, 42 bytes
K
zz
OZ
zzz+
OZd*
OdZ/
zzzz*
Ozz+-
OdZ-
Oz-
O
Od+dz++
Results
0
1
2
3
4
5
6
7
8
9
10
42
There aren't many ways to generate new numbers with dc. I use O: output base, initially 10; K: precision, initially 0; z stack depth, initially 0; Z significant digits of operand. We combine these with the usual arithmetic operators.
Test program
#!/bin/bash
progs=( \
"K" \
"zz" \
"OZ" \
"zzz+" \
"OZd*" \
"OdZ/" \
"zzzz*" \
"Ozz+-" \
"OdZ-" \
"Oz-" \
"O" \
"Od+dz++" \
)
a=0
results=()
for i in "${progs[@]}"
do
results+=($(dc -e "${i}p"))
(( a+=${#i} ))
done
echo "#dc, $a bytes"
echo
printf ' %s\n' "${progs[@]}"
echo
echo '##Results'
echo
printf ' %s\n' "${results[@]}"
๐ผ๐๐๐๐, 36 bytes (12 chars)
แธ
แธ
แธ
แธ
แธ
แธ
แธ
แธ
แธ
แธ
แธ
แธช
Try it here (test-suite-style, Firefox only).
There are variables for numbers from 0-256. (One of the benefits of choosing from UTF-8 is that you can dedicate a whole charset of 256 characters just to this kind of stuff. (Of course, byte count is a side effect.))
Python 2, 191 159 158 157 156 149 146 bytes
My first submission ever, I hope I got everything right ! Based on the time I spent on this, I guess there's surely a better one for a few of them.
# 0 | Bytes : 5
int()
# 1 | Bytes : 5
+True
# 2 | Bytes : 6
-~True
# 3 | Bytes : 8
-~-~True
# 4 | Bytes : 10
-~-~-~True
# 5 | Bytes : 12
-~-~-~-~True
# 6 | Bytes : 14
-~-~-~-~-~True
# 7 | Bytes : 16
-~-~-~-~-~-~True
# 8 | Bytes : 15
a=True;a<<a+a+a
# 9 | Bytes : 19
a=True;(a<<a+a+a)+a
# 10 | Bytes : 20
int(`+True`+`int()`)
# 42 | Bytes : 16
~-len(`license`)
# Especially proud of this one !
Total byte count: 146
Many thanks to FryAmTheEggman !
Seriously, 39 33 bytes
Stuff in parentheses is explanations:
(single space, pushes size of stack, which is 0 at program start)
u (space pushes 0, u adds 1 (1))
โ (space pushes 0, โ adds 2 (2))
uโ (space pushes 0, u adds 1 (1), โ adds 2 (3))
โโ (space pushes 0, โโ adds 2 twice (4))
โP (space pushes 0, โ adds 2 (2), P pushes the 2nd prime (5))
Hlโ (H pushes "Hello, World!", l pushes length (13), โ pushes pi(13) (6))
QlP (Q pushes "QlP", l pushes length (3), P pushes the 3rd prime (7))
Qlโ (Q pushes "QlP", l pushes length (3), โ pushes 2**3 (8))
รบlโ (รบ pushes the lowercase English alphabet, l pushes length (26), โ pushes pi(26) (9))
uโค (space pushes 0, u adds 1 (1), โค pushes 10**1 (10))
HlPD (H pushes "Hello, World!", l pushes length (13), P pushes the 13th prime (43), D subtracts 1 (42))
Hexdumps of programs:
20
2075
20a9
2075a9
20a9a9
20a950
486cb2
516c50
516cd3
a36cb2
2075d1
486c5044
Thanks to quintopia for 6 bytes!
R, 123 bytes
+!pi # 0 - 4 bytes
+TRUE # 1 - 5 bytes
nchar(NA) # 2 - 9 bytes
floor(pi) # 3 - 9 bytes
cars$d[pi] # 4 - 10 bytes
ncol(CO2) # 5 - 9 bytes
nrow(BOD) # 6 - 9 bytes
cars$s[pi] # 7 - 10 bytes
sum(dim(BOD)) # 8 - 13 bytes
floor(pi*pi) # 9 - 12 bytes
ceiling(pi*pi) # 10 - 14 bytes
nrow(CO2)/nchar(NA) # 42 - 19 bytes
# Total 123 bytes
C, 202 bytes
enum{a}; // 0, 8
enum{a,b}; // 1, 10
enum{a,b,c}; // 2, 12
enum{a,b,c,d}; // 3, 14
enum{a,b,c,d,e}; // 4, 16
enum{a,b,c,d,e,f}; // 5, 18
enum{a,b,c,d};c*d; // 6, 18
enum{a,b,c,d,e};d+e; // 7, 20
enum{a,b,c};c<<c; // 8, 17
enum{a,b,c};b+(c<<c); // 9, 21
enum{a,b,c};c+(c<<c); // 10, 21
enum{a,b,c,d,e,f};c*f*e+c; // 42, 26
Printed Version, 730 bytes
enum{a,b,c,d,e};char m[d]={(d<<e)+a,a};main(){printf(m);} // 0, 57
enum{a,b,c,d,e};char m[d]={(d<<e)+b,a};main(){printf(m);} // 1, 57
enum{a,b,c,d,e};char m[d]={(d<<e)+c,a};main(){printf(m);} // 2, 57
enum{a,b,c,d,e};char m[d]={(d<<e)+d,a};main(){printf(m);} // 3, 57
enum{a,b,c,d,e};char m[d]={(d<<e)+e,a};main(){printf(m);} // 4, 57
enum{a,b,c,d,e};char m[d]={(d<<e)+e+b,a};main(){printf(m);} // 5, 59
enum{a,b,c,d,e};char m[d]={(d<<e)+e+c,a};main(){printf(m);} // 6, 59
enum{a,b,c,d,e};char m[d]={(d<<e)+e+d,a};main(){printf(m);} // 7, 59
enum{a,b,c,d,e};char m[d]={(d<<e)+e+e,a};main(){printf(m);} // 8, 59
enum{a,b,c,d,e,f};char m[d]={(d<<e)+f+e,a};main(){printf(m);} // 9, 61
enum{a,b,c,d,e,f,g,h,i,j,k};char m[d]={k*d+h,k*k,a};main(){printf(m,k);} // 10, 72
enum{a,b,c,d,e,f,g,h,i,j,k};char m[d]={k*d+h,k*k,a};main(){printf(m,k*e+c);} // 42, 76
PHP, 157 145 91 bytes
First time posting on Code Golf, figured I'd give it a shot. I'll get better eventually :P If you see any obvious (to you) spots where I could save characters, let me know.
EDIT: Realized I didn't need the semicolons, since these are just snippets.
EDIT2: Thanks to Blackhole for many suggestions!
LC_ALL
DNS_A
~~M_E
~~M_PI
LOCK_NB
LC_TIME
LOG_INFO
INI_ALL
IMG_WBMP
SQL_DATE
SQL_TIME
LOG_INFO*INI_ALL
Prolog, 113 99 bytes
Snippets:
e-e % 0.0
e/e % 1.0
e/e+e/e % 2.0
ceil(e) % 3
ceil(pi) % 4
ceil(e*e-e) % 5
ceil(e+e) % 6
floor(e*e) % 7
ceil(e*e) % 8
ceil(pi*e) % 9
ceil(pi*pi) % 10
ceil(e^e*e) % 42
Combines the mathematical constants e and pi in different ways converted to int.
Edit: Saved 14 bytes by utilizing floats for 0-2.
Javascript (Browser Env), 155 136 130 bytes
+[]
-~[]
-~-~[]
-~-~-~[]
-~-~-~-~[]
-~-~-~-~-~[]
-~-~-~[]<<-~[]
-~-~-~-~-~-~-~[]
-~[]<<-~-~-~[]
~(~[]+[]+-[])
-~[]+[]+-[]
-~(top+top.s).length // Requires browser environment
Thanks to:
@Ismael Miguel: 155 -> 136 -> 130 bytes
Pyth, 35 34 33 bytes
-1 byte by @Mimarik
There are a number of possibilities for some programs.
0, 1 byte
Z
1, 2 bytes
hZ
!Z
2, 3 bytes
hhZ
eCG
eCd
lyd
lyb
lyN
3, 3 bytes
l`d
4, 3 bytes
l`b
eCN
5, 4 bytes
hl`b
telG
6, 3 bytes
elG
7, 4 bytes
tttT
helG
8, 3 bytes
ttT
9, 2 bytes
tT
10, 1 byte
T
42, 4 bytes
yhyT
All of these involve either basic double (y), +1 (h) and -1 (t) commands, or l (length of a string). The Z variable is initialized to zero.
For 5, b is initialized to a newline character. Backtick gives "\n" (including the quotes, and the length of that string is 4.
Try them here!
Marbelous, 98 bytes
Not terribly exciting, it relies on the ?n devices which turn any marble into a random value in the range 0..n (inclusive) a side effect of this is that ?0 turns any marble into a 0 regardless of input. I think the use of literals is permitted because the value does not affect the outcome and there is no other way to call a function once in Marbelous.
0:
00 # A hexadicemal literal: value 0
?0 # Turn any marble into a random value from the range 0..0 (inclusive)
1:
00
?0
+1 # increment by one
...
9:
00
?0
+9
10:
00
?0
+A # increment by 10
42:
00
?0
+L # increment by 21
+L
Pyth, 50 40 bytes
Z
hZ
hhZ
hhhZ
hhhhZ
hhhhhZ
ttttT
tttT
ttT
tT
T
yhyT
In Pyth, Z=0 and T=10. h is head, which means the next variable + 1. (e.g. hhZ == 2). t is tail, which means the next variable - 1 (e.g. tttT == 7). The last line is the fanciest: we essentially do double(1 + double(10)).
Python 2, 306 275 274 bytes
I used the fact that for any x (integer and not 0) the expression x/x equals 1 and played around with some bitwise operations.
I adjusted the snippets such that they still meet the requirements (thanks @nimi this saved me 24 bytes), but you have to manually test them. Here is the code and individual byte counts:
zero.py Bytes: 7
len({})
--------------------------
one.py Bytes: 12
r=id(id)
r/r
--------------------------
two.py Bytes: 17
r=id(id)
-(~r/r)
--------------------------
three.py Bytes: 20
r=id(id)
-(~r/r)|r/r
--------------------------
four.py Bytes: 20
r=~id(id)/id(id)
r*r
--------------------------
five.py Bytes: 26
r=~id(id)/id(id)
(r*r)|r/r
--------------------------
six.py Bytes: 25
r=~id(id)/id(id)
(r*r)|-r
--------------------------
seven.py Bytes: 27
r=~id(id)/id(id)
-~(r*r|-r)
--------------------------
eight.py Bytes: 24
r=-(~id(id)/id(id))
r<<r
--------------------------
nine.py Bytes: 29
r=-(~id(id)/id(id))
r-~(r<<r)
--------------------------
ten.py Bytes: 31
r=~id(id)/id(id)
-r*((r*r)|r/r)
--------------------------
answer.py Bytes: 37
r=-(~id(id)/id(id))
(r<<r*r)|(r<<r)|r
--------------------------
Total byte count: 274
k4, 41 bytes
Most of this is a cheap hackโevery builtin function in k has an internal id number, and . retrieves them. Entries of the form .(x) are implemented thus; others are commented.
A question: are we supposed to generate the numbers or print them? E.g., for zero, should we return some numeric type containing zero as a value, or should we display the exact string 0? I ask because in there are several default settings that could be useful here, but they all have (32-bit) integer type, which means that in recent (3.x) versions of q/k4, they are displayed on the console with a type suffix of i appended. The following assumes 0i is a valid form of 0, but has alternatives in the comments.
\p / 0: the default network port (none); alternatively, #(), the count of the empty list
#` / 1: the count of a null symbol atom; alternatively, if this is considered a character literal, use .(+)
\W / 2: the default starting day of the week (monday), counting from saturday as 0; alternatively, .(-)
.(*) / 3
.(%) / 4
#!` / 5: the number of namespaces loaded by default (works in 3.2 or 3.3; in earlier versions, use this as 4 and .(&) as 5)
.(|) / 6
\P / 7: the default numeric precision (7 significant figures); alternatively, #.j, the count of the .j namespace; alternatively, .(^)
.(=) / 8
.(<) / 9
.(>) / 10
.(var) / 42
TI-BASIC, 41 bytes
0~10:
X
cosh(X
int(e
int(ฯ
-int(-ฯ
int(โ(ฯยณ
int(ฯ+ฯ
int(eยฒ
int(eฯ
int(ฯยฒ
Xmax
42:
int(ฯยฒ/ecosh(ฯ
In TI-BASIC, all uninitialized single-letter variables start at 0, and Xmax (the right window boundary of the graph screen) starts at 10.
The mathematical constant ฯ is one byte, but e is two bytes.
Darkness, 339 303 bytes
This is where Darkness really shines. Get it? :~)!
Without printing (replaced the space with \s in the first line since it won't show otherwise):
\s
โ
โโ
โโโ
โโโโ
โโโโโ
โโโโโโ
โโโโโโโ
โโโโโโโโ
โโโโโโโโโ
โโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
With printing:
โ
โโ
โโโ
โโโโ
โโโโโ
โโโโโโ
โโโโโโโ
โโโโโโโโ
โโโโโโโโโ
โโโโโโโโโโ
โโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Each line must be run individually in this case since the program terminates in the light (a space). However, it is possible to write this on one or several lines in the same program.
Regular darkness (โ) increments a register by 1, and the โ instruction (some sort of mini-darkness) outputs the contents of the register.
D1ffe7e45e, 112
0
02
020
0202
02020
020202
0202020
02020202
020202020
0202020202
02020202020
202020202020202020202020202020202020202020
Each line is a different snippet.
The numbers in the program don't count as number literals since they're only used as commands.
The final one can definitely be golfed more.
EDIT: I got the interpreter working and all snippets work. If you'd like to test if yourself, add 0f0f to the end of the snippet so the program terminates.
Japt, 34 33 30 bytes
1 byte saved thanks to @ThomasKwa
T
ยฐT
C-A
D-A
E-A
F-A
G-A
ยฐG-A
Iq
ยดA
A
H+A
Here's what each of the different chars means:
T 0
A 10
B 11
C 12
D 13
E 14
F 15
G 16
H 32
I 64
q sqrt on numbers
ยฐ ++
ยด --
O, 36 bytes
l Nl CA- DA- EA- FA- FA-) A((( A(( A( A A.+.+))
Mostly finding the difference of hex letters,
CA- = 13-11 = 2
DA- = 14-10 = 3
( and ) decrement and increment respectively,
A(( = 10-1-1 = 8
.+ duplicates the top of the stack and adds it together
A.+.+))
10.+.+))
20.+))
40))
42
The first two get the length of the stack (l), which zero, or one when a blank CodeBlock is pushed to the stack (N).
Javascript, 159 chars
No any variables
Any line between ` is a code snippet. The whole code is a test. It returns an array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42]. If returning string "42" instead of number 42 is ok, code can be made 3 schars less (remove |[]).
`
+[]
-~[]
!![]+!![]
~~Math.PI
-~Math.PI
-~Math.PI|!![]
Math.PI<<!![]
Math.PI<<!![]|!![]
!![]<<Math.PI
Math.PI*Math.PI^[]
(-~Math.PI|!![])<<!![]
-~Math.PI+[]+(!![]+!![])|[]
`.split('\n').filter(Boolean).map(eval)
Mathematica, 101 bytes
a-a
a/a
โEโ
โEโ
โฯโ
โE+Eโ
โE+Eโ
โE*Eโ
โE*Eโ
โE*ฯโ
โฯ*ฯโ
โฯ*ฯ^ฯ/Eโ
I'm pretty sure some of these are suboptimal. Those rounding brackets are really expensive.
For consistency, the first two could also be E-E and E/E of course, but I thought it's quite nifty to get 0 and 1 from a computation with undefined variables.
Brainfuck, 70 bytes
+
++
+++
++++
+++++
++++++
+++++++
++++++++
+++++++++
++++++++++
--[>+<++++++]>-
Each line must be run individually.
The first 10 are self explanatory: we increment the value of the cell via each plus.
The 42 is a lot more complex. It relies on the fact the most brainfuck interpreter use 8-bit cells, meaning that all operations on it are done modulo 256. The -- sets cell #0 to 254. Then we enter a loop which runs until cell #0 is 0. Each iteration adds 1 to cell #1 and adds 6 to cell #0. This loops runs 43 times, so cell #1 is 43. Finally, we subtract 1 from cell #1 to make it 42.
I got the most efficient 42 ever found from http://esolangs.org/wiki/Brainfuck_constants
CJam, 27 24 bytes
U e# 0
X e# 1
Y e# 2
Z e# 3
Z) e# 3 + 1
YZ+ e# 2 + 3
ZZ+ e# 3 + 3
AZ- e# 10 - 3
YZ# e# 2ยณ
A( e# 10 - 1
A e# 10
EZ* e# 14 ร 3
Thanks to @MartinBรผttner for -1 byte!
MATL, 30 bytes
O
l
H
I
K
Kl+
HI*
KYq
HK*
IH^
K:s
IH^:sI-
H, I, and K are predefined constants for 2, 3, and 4 (like pi). O and l are functions that returns a matrix of zeros (O) or ones (l), the default size is 1x1. : makes a vector, and s sums it, so K:s makes a vector from 1 to 4 and sums it to get 10. Yq is the n-th prime function, so KYq is the 4th prime, 7.
dc, 44
Score does not include newlines between each snippet.
If CJam's U, X, Y, Z, and A constants are allowed, then I assume dc's representation of 10-15 as A-F is also OK.
z
zZ
CI-
DI-
EI-
FI-
II+E-
II+D-
II+C-
II+B-
A
IB+CI-*
@yeti's answer is better.
