No strings (or numbers) attached

70

6

If you like this, consider participating in:


Make 12 snippets/expressions, in the same language, that result in the numbers 0 through 10, and 42 respectively, but without writing any literal numeric, string, or character data.

Build-in data, like PI() and ALPHABET(), are fine, and so are e.g. CJam's U, X, Y, Z, and A constants, and Processing's BLEND, CHORD, CENTER, BREAK, and LINES.

Every snippet must be able to stand on its own, i.e. they may not be interdependent. However, inside a single snippet, you may assign a variable and use it freely, as long as you refer to it directly by name, and not through a string containing its name.

All the snippets must be valid on the submitter’s computer at the time of submission (as reported by SE), but may not rely on unusual local conditions like number of files in a directory, the exact date or time, or specific input from the user.

Examples of valid snippets

3: INT(LOG10(YEAR(TODAY()))) because it remains true in the foreseeable future
4: CUBICROOT(LEN(CHARACTERSET())) because a 256 letter character set is very common
8: SQRT(SYSTEMTYPE()) because 64-bit systems are very common

Examples of invalid snippets

5: LEN(USERNAME()) because most people do not use “Admin” as login :-)
9: LOG10(SYSTEMMEMORY()) because it only works on systems with exactly 1 GB of memory
42: CODE("*") because it contains a string/character literal

The result of each snippet must result in an actual number (value, int, float, etc.) that can be used for further calculations using the same language as the snippet, i.e not a text string representing that number.

Only character based languages allowed.

Score is total byte count of all the 12 snippets combined. Newlines separating the snippets are not counted in.

Note that the above rules may prevent some languages from participating, even if they are Turing complete.

FAQ

Q Can the programs accept any input?
A Yes, but you may not just ask for input and enter the relevant number.

Q Are physical digits (non-data) digits allowed?
A Yes, e.g. LOG10().

Q Do Symbols in Ruby count as literals?
A Yes.

Q Does score include newlines between each snippet?
A No.

Q Is TI-BASIC "character based" enough to be valid?
A Yes.

Q Do false and true count as number literals?
A No, they are acceptable.

Q Can we use a number literal to call a function if that's the only way and the number doesn't influence the output of the function?
A Yes, if that is the normal way to write code in your language.

Q My language assumes there is a [something] at the start of each program/expression. Must I include it, or should my snippets just work if placed in the middle of a program/expression?
A They should just work in the middle of a program/expression.

Q What about regex literals?
A Forbidden, except for languages that only do regexes.

Q Is one piece of code that could print all the specified numbers acceptable?
A No, they have to be separate and mutually independent.

Q May I assume a boilerplate like int main() {}... or equivalent?
A Yes.

Q What output datatypes are allowed?
A Any numeric datatype, like int, float, etc.

Q Do I need to print the result of each snippet?
A No, making the result available for subsequent use is enough.

Q Are pre-set variables allowed?
A Yes, and they become reset (if changed) for every snippet.

Q Are π and e considered number literals?
A No, you may use them.

Q May I return 4 and 2 in different cells for 42?
A No, they must be connected as one number.

Q Bytes or characters?
A Bytes, but you may choose any desired codepage.

Q May constant functions and preset variables like J's 9:, Actually's 9, and Pretzel's 9 be used?
A Yes, if the vocabulary is finite (19 for J, 10 for Actually and Pretzel).

Adám

Posted 2015-12-17T19:32:46.753

Reputation: 37 779

If 0-9 are not number literals but are pre-populated variables, would they be fair game? – Cyoce – 2016-08-28T07:58:32.327

@Cyoce So 10 is {1, 0} and not 2×5? – Adám – 2016-08-29T09:34:03.190

no, there is simply another syntax for literals that is not base-10, so 0-9 are not literals. They hold the value of 0-9, but are considered variables – Cyoce – 2016-08-29T15:17:37.180

@Cyoce Then it's fine. What language is that? – Adám – 2016-08-29T18:56:36.450

pretzel (a language I'm working on). – Cyoce – 2016-08-29T22:47:33.483

Do numbers in languages such as Sesos (non-competing) count as literals?

– Erik the Outgolfer – 2016-10-05T18:17:16.990

@EriktheGolfer Why should(n't) they be? – Adám – 2016-10-06T15:48:38.057

@Adám Because the SBIN is the actual program. The literals appear as such in the SASM, but I don't know... I think they count, though, so Sesos is definitely out. I think it's like C, where the pre-compiled form of the code has literals that count as such. – Erik the Outgolfer – 2016-10-06T15:53:18.340

@Adám, What about using undefined constants? PHP has a default value for undefined constants, which is the name of the constant. – aross – 2017-02-14T11:23:18.423

@aross Sounds fine to me. Can you give an example? – Adám – 2017-02-14T11:24:30.790

@Adám A constant ╦═ (IBM-850), which is the binary negation of string 42. It's not very creative, but it is short :) – aross – 2017-02-14T11:48:43.020

@aross Go ahead. – Adám – 2017-02-14T11:51:28.633

Answers

15

Hexagony, 13 bytes

1
2
3
4
5
6
7
8
9
10
42

Try it online!

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.)

Leaky Nun

Posted 2015-12-17T19:32:46.753

Reputation: 45 011

Sneaky, but gets my upvote and tick. – Adám – 2016-08-23T13:30:32.110

49

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).

Timwi

Posted 2015-12-17T19:32:46.753

Reputation: 12 158

6

+1 for the Ackermann function.

– intrepidcoder – 2015-12-18T18:42:57.830

4I wish I could upvote more than once... – ev3commander – 2015-12-19T00:28:40.523

26

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>

user81655

Posted 2015-12-17T19:32:46.753

Reputation: 10 181

Try 4: -~Math.PI – edc65 – 2015-12-18T07:32:24.760

@edc65 Thanks! I thought there would be something I could do with PI. :) – user81655 – 2015-12-18T07:34:49.450

For 5, 6 you can also use -~-~Math.PI and -~-~-~Math.PI saving another byte (twice). – Sjoerd Job Postmus – 2015-12-18T13:48:42.367

@SjoerdJobPostmus Oh of course! Thanks for catching that. – user81655 – 2015-12-18T14:25:58.287

You can save one on 9 with (a=~Math.E)*a – DocMax – 2015-12-18T20:31:49.493

Use +[] for 0 (saves 1 byte). – usandfriends – 2015-12-18T20:39:19.123

Save one on 42 with: (a=-~-~-~Math.PI)*(++a) – DocMax – 2015-12-18T20:45:32.710

Save two on 10 with (a=-~!![])<<a^a – Charlie Wynn – 2016-03-01T18:25:08.807

Save four on 7 with Date.length – Mwr247 – 2016-03-01T21:49:24.503

1Save one on 42 with (escape+NaN).length. P.S. Today I learned that JavaScript is really weird... – Mwr247 – 2016-03-01T22:17:25.957

@Mwr247 Nice, thanks! Functions seem to cast to strings differently depending on the JavaScript implementation so I included your 42 solution as a comment. – user81655 – 2016-03-02T00:52:06.780

(a=Date.length)*--a does 42 in 19 bytes – Charlie Wynn – 2016-03-02T21:29:53.437

1I was gonna say that NaN counts as a number, but it's literally Not a Number :P – ETHproductions – 2016-03-02T21:44:27.357

17

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+

cat

Posted 2015-12-17T19:32:46.753

Reputation: 4 989

It says "a snippet or expression" so you can remove all the !'s – ev3commander – 2015-12-19T00:45:41.670

3@cat I can't speak for the questioner, but I think that means stand alone from each other - no defining a function in one, then using it in another. However, each snippet doesn't need to be an entire program, it can assume the boilerplate int main() {}... equivalent that will make it run. – TessellatingHeckler – 2015-12-19T03:16:37.680

15

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!

Try it online!

Dennis

Posted 2015-12-17T19:32:46.753

Reputation: 196 637

12

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!

Doorknob

Posted 2015-12-17T19:32:46.753

Reputation: 68 138

3

Perl is strange. http://www.zoitz.com/comics/perl_small.png

– ldam – 2015-12-18T15:49:52.397

downgoated because "max sys file descriptor number, 2 on all sane systems = 3" but i have 65+ – cat – 2015-12-20T12:28:47.257

(i'm just joking, i upvoted of course) – cat – 2015-12-20T12:29:34.297

1You ever read the comments on an SE post and think, "wow, which dumbass wrote that"? That's me right now, at myself. – cat – 2016-03-01T22:13:35.737

!$[+ord$/ # -1 + 10 — I don’t understand. In line 2 you say that !$[ gives you 1, not −1, so this snippet gives 11. – Timwi – 2016-03-06T13:50:45.823

@Timwi Whoops, I must have missed the - while copying that one down. Thanks! – Doorknob – 2016-03-06T20:28:42.923

@DomHastings Your snippet for 7 results in 20 for me, and the one for 42 is actually 32. The others do work, though; thanks! – Doorknob – 2016-10-25T14:18:07.607

@DomHastings Ah, you're right about 7. As for the 42 one, now I get 48 when running it instead (?!?). That's super weird, since neither of those variables are things that should change... – Doorknob – 2016-10-25T14:57:00.177

Well, anyway, it seems to work when called in a brand new session (perl -e ...); I was testing all of these in the same debug session before. I'll go ahead and add that one in also, thanks! – Doorknob – 2016-10-25T14:59:31.297

Just noticed another one too: 9 ++$^F*$^F! Was really annoyed that ~~$] didn't work for 5. Don't understand why (or how...) it's handled differently to other variables: perl -E 'say~~$];say~~eval$]'... $]|$- works correctly, but is no shorter. Perl is strange. :) – Dom Hastings – 2016-10-25T15:12:20.727

12

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

p1xel

Posted 2015-12-17T19:32:46.753

Reputation: 241

1@someonewithpc 4 and 2 is different from 42: the OP says The result of each snippet must result in an actual number that can be used for further calculations using the same language as the snippet, i.e not a text string representing that number. You can do calculations on 42 directly, but it's not the same for 4 and 2 in separate cells. – p1xel – 2015-12-19T23:00:15.480

Oh, ok. I had missed that.. – someonewithpc – 2015-12-19T23:01:25.550

12

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.

sweerpotato

Posted 2015-12-17T19:32:46.753

Reputation: 2 457

I don't think this asks for full programs, just snippets. – Erik the Outgolfer – 2016-10-06T15:59:12.400

10

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.

Emigna

Posted 2015-12-17T19:32:46.753

Reputation: 50 798

1anything wrong with e/e=1? – Level River St – 2015-12-17T22:29:03.757

@steveverrill: it will become a float (1.0). I interpreted the challenge description to mean that the numbers should be integers. Most of these, if not all could be shortened otherwise. – Emigna – 2015-12-18T07:18:36.160

1@steveverrill Floats are fine. We just need the right value. – Adám – 2015-12-20T03:29:56.253

10

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.

David

Posted 2015-12-17T19:32:46.753

Reputation: 1 316

That Yq function (and its implementation) was a very nice suggestion of yours :-)

– Luis Mendo – 2015-12-18T01:26:48.377

IK+ would work just as well for 7, but it's a bit too boring :P – David – 2015-12-18T02:34:03.650

9

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.

Timwi

Posted 2015-12-17T19:32:46.753

Reputation: 12 158

Would the rules allow you to do something like var a = new int(); and then use a in each snippet? – ldam – 2015-12-18T15:51:35.563

@LoganDam: I find it more interesting if every expression has to stand on its own. That’s also why I didn’t use any using declarations. – Timwi – 2015-12-18T22:57:46.673

Whoa what are those for 9/10/42 :Oo – ev3commander – 2015-12-19T00:35:25.960

@ev3commander: They are simply the shortest-named enum values defined in mscorlib that have the necessary integer value. For ConsoleKey.Tab, the value 9 is not surprising (9 is also the ASCII of the tab character). The others are probably arbitrary. – Timwi – 2015-12-19T01:49:18.850

Shorter one for 8: int a=-~-~new int();a<<a – LegionMammal978 – 2015-12-25T23:51:21.017

@LegionMammal978: Nice! However, you can’t use that inside an expression, so I’m not sure I’d count it... – Timwi – 2015-12-27T12:13:29.470

9

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

orp

Posted 2015-12-17T19:32:46.753

Reputation: 241

5

PHP has a lot of extensions, and therefore a lot of predefined constants far better than the mathematical ones for this challenge ;). LC_ALL for 0 (-1 byte), DNS_A for 1 (-3 bytes), LOCK_NB for 4 (-3 bytes), LC_TIME for 5 (-7 bytes), LOG_INFO for 6 (-8 bytes), INI_ALL for 7 (-5 bytes), …

– Blackhole – 2015-12-19T20:33:20.990

5

IMG_WBMP for 8 (-4 bytes), SQL_DATE for 9 (-9 bytes), SQL_TIME for 10 (-3 bytes) and LOG_INFO*INI_ALL for 42 (-11 bytes). Hence a total of 51 bytes saved! These constants are valid at least in PHP 5.6.1 on Windows.

– Blackhole – 2015-12-19T20:33:30.187

@Blackhole isn't LC_ALL a locale dependent thing? – cat – 2015-12-20T12:22:49.763

@cat It's indeed a constant used with setlocale() to change all the categories of locales. But the value of the constant itself is of course independent of the locale :).

– Blackhole – 2015-12-20T14:49:10.780

@Blackhole ah, i see! – cat – 2015-12-20T14:50:14.773

@Blackhole: Sorry, I was inactive for a couple days. Thanks for the help! – orp – 2015-12-21T13:35:38.100

9

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 - -bnot in PowerShell.

  • x^y exponentiation used in Perl answers, or x**y in Python or JavaScript ES7, would be [Math]::Pow($x,$y)

  • constants e and Pi are the character-heavy [Math]::E and [Math]::PI

TessellatingHeckler

Posted 2015-12-17T19:32:46.753

Reputation: 2 412

x^y is xor in JavaScript. JavaScript (ES7) has ** for exponents. Source – mbomb007 – 2016-03-03T16:18:16.897

@mbomb007 Ah, thanks - I've updated my note on that. – TessellatingHeckler – 2016-03-04T03:56:55.823

@mbomb007 I still think that's kind of silly – SuperJedi224 – 2016-03-15T15:50:23.117

@SuperJedi224 Why? That's how Python does it. And xor is an important operator. – mbomb007 – 2016-03-15T16:23:57.437

9

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 !

Joachim Jablon

Posted 2015-12-17T19:32:46.753

Reputation: 191

Welcome to PPCG :) I'm not 100% sure about this challenge but I think using True as an idiom for 1 should be acceptable, as I don't know when they aren't equivalent as snippets. – FryAmTheEggman – 2015-12-20T21:59:29.473

Oh, you're right ! Not using it for the 1 itself, because True is not 1 but for all the computation based on 1, it helps ! Editing now. – Joachim Jablon – 2015-12-20T22:02:47.453

1

Use #8 len(\id(id)`)`. Then 8, 9, and 10 will be shorter. Also, maybe add a hyperlink to Try it online.

– mbomb007 – 2016-03-03T16:12:33.170

You can get 9 with len(`{()}`) for 11 bytes, and that gives you 7 through 10 shorter. – xnor – 2016-08-25T23:06:34.780

8

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

user19214

Posted 2015-12-17T19:32:46.753

Reputation:

I believe that E and F here are digits (even when they are greater than the input radix). Evidence for this is that they combine as digits; e.g. F0 -> 150. You can see the same behaviour with decimal digits once you change input and output radix. – Toby Speight – 2016-03-02T08:52:14.643

There are lots of other answers using similar stuff... why should I be the only one where this is not ok? – None – 2016-03-02T09:26:08.833

You shouldn't - if there are other solutions using digits, then they aren't valid answers either. – Toby Speight – 2016-03-02T09:27:31.067

1I don't care any more! Codegolf even accepts a graphic mandelbrot set program as solution to the task to write an ascii art mandelbrot program... codegolf needs a big reset and when restarted I may or may not care about rules again... :-Þ – None – 2016-03-02T09:29:30.347

7

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.

lirtosiast

Posted 2015-12-17T19:32:46.753

Reputation: 20 331

Isn't π considered numeric data? – vsz – 2015-12-18T12:35:07.673

@vsz perhaps, but it isn't a number literal. The op even says so. – SuperJedi224 – 2015-12-18T14:01:31.460

@NBZ very good point. My bad. – GamrCorps – 2015-12-20T04:35:32.370

6

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)

SuperJedi224

Posted 2015-12-17T19:32:46.753

Reputation: 11 342

6

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

ბიმო

Posted 2015-12-17T19:32:46.753

Reputation: 15 345

You can save bytes with i=id(id);r=~i/i – Cyoce – 2016-08-26T16:52:18.480

5

Javascript (Browser Env), 155 136 130 bytes

+[]
-~[]
-~-~[]
-~-~-~[]
-~-~-~-~[]
-~-~-~-~-~[]
-~-~-~[]<<-~[]
-~-~-~-~-~-~-~[]
-~[]<<-~-~-~[]
~(~[]+[]+-[])
-~[]+[]+-[]
-~(top+top.s).length // Requires browser environment

Thanks to:
@Ismael Miguel: 155 -> 136 -> 130 bytes

usandfriends

Posted 2015-12-17T19:32:46.753

Reputation: 687

1You can use -~[]+[]+-[] to produce 10. It will return a string, but it's still usable as a number. Also, you can use -~(top+top.s).length to calculate 42 (-8 bytes) and drop your dependency on Google Chrome. To save more 3 bytes, use (P=Math.PI)*P>>+[] to calculate 9. – Ismael Miguel – 2015-12-18T19:57:51.477

1Sorry, forgot a few bytes you can shave. You can use ~(~[]+[]+-[]) to generate 9. That should cut down a few more bytes. – Ismael Miguel – 2015-12-18T23:06:59.693

curiously, +[12] gives 12 and +[1, 2] gives NaN. I hate JS – cat – 2015-12-19T12:56:32.903

2@cat It's because of JavaScript's weird cast system. Arrays cast to strings like [1,2,3] => "1,2,3" and strings cast to numbers like "12" => 12 but if there are non-number characters in the string the cast returns NaN. +[1,2] casts to a string then a number but the string contains a comma so "1,2" becomes NaN. – user81655 – 2015-12-19T22:56:01.153

@user81655 that. is. HORRID. – cat – 2015-12-19T23:00:32.290

5

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!

Mego

Posted 2015-12-17T19:32:46.753

Reputation: 32 998

1I suppose Seriously uses a 256 char codepage that includes pseudo graphic chars? – Adám – 2015-12-18T14:34:59.680

2

@NBZ CP437

– Mego – 2015-12-18T15:46:02.020

You can save a byte on 6 with Hl▓ – quintopia – 2015-12-20T14:19:26.423

The same idea with ú saves a byte on 9 – quintopia – 2015-12-20T14:28:05.940

HlPD saves 2 bytes on 42, and QlP saves a byte on 7, and Qlª saves a byte on 9, and Ql╙ saves a byte on 8. I think that gets Seriously down to 33 bytes all told, tying Pyth. – quintopia – 2015-12-21T04:31:18.423

5

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[@]}"

Toby Speight

Posted 2015-12-17T19:32:46.753

Reputation: 5 058

4

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
°    ++
´    --

ETHproductions

Posted 2015-12-17T19:32:46.753

Reputation: 47 880

Does Japt take hexadecimal numbers by default? If so, then A through F would be numeric literals... – Adám – 2015-12-21T14:10:31.347

@NBZ A-I are variables that are, by default, assigned to various numbers, as shown above. A-F are assigned to 10-15. Does this invalidate those variables? – ETHproductions – 2015-12-21T14:52:09.410

No. I was just wondering if, say 12AB3 was valid. Now I know it isn't. No literals here, move along. :-) – Adám – 2015-12-21T17:31:33.790

4

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.

Martin Ender

Posted 2015-12-17T19:32:46.753

Reputation: 184 808

@NBZ Sorry, forgot about 0. If a gets the value 0 afterwards, that's not an issue, as long as it's unused when a/a is evaluated. – Martin Ender – 2015-12-18T14:37:10.167

@NBZ The byte count is simply the UTF-8 byte count. – Martin Ender – 2015-12-18T14:37:32.427

4

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

overactor

Posted 2015-12-17T19:32:46.753

Reputation: 3 500

It sure looks like 0...L are numeric literals. – Adám – 2015-12-20T12:50:27.503

2@NBZ They're not, you can't use them independently. +0 through +Z are like builtin functions. It's boring but valid. – overactor – 2015-12-20T14:10:04.923

4

DUP, 68 bytes

[
 [
  [
[)]!
[ )]!
[  )]!
[)~_]!
[ )~_]!
[  )~_]!
[   )~_]!
[)$+]!
[ )$+~_$+]!

Try it here.

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!

Mama Fun Roll

Posted 2015-12-17T19:32:46.753

Reputation: 7 234

4

><>, 86 bytes

  • 0: ln;
  • 1: lln;
  • 2: llln;
  • 3: lll+n;
  • 4: lll:+n;
  • 5: llll+n;
  • 6: llll++n; or llll:+n;
  • 7: lllll+n;
  • 8: lllll:+n;
  • 9: lllll++n; or llllll+n;
  • 10: llll+:+n; or lll:l+*n;
  • 42: llll*ll+*n;

Relies on stack size to get its literals.

Aaron

Posted 2015-12-17T19:32:46.753

Reputation: 3 689

You can probably remove the n on each because functions in stack-based languages can leave the output on the stack for -11 bytes.

– redstarcoder – 2016-12-05T14:43:52.163

@redstarcoder then I could even remove the ; for a total of 22 bytes and consider the end of the function reached at the end of the line, but it's a little ambiguous since ><> doesn't have out-of-the-box functions. – Aaron – 2016-12-05T15:29:47.220

Technically if you want functions in ><>, your functions have to accept a return position (x & y) on the stack in addition to their parameters, make sure these aren't in the way while doing calculations ([ comes in handy in that context), then jump to the return position after having finished execution. I had done a POC a while ago, check it out if you're interested

– Aaron – 2016-12-05T15:36:21.517

I've actually seen your post before, and good work! I did a meta post about the ambiguities of functions. What I'm saying is this is typically allowed, with the ;. The reason I say to leave in ; is because otherwise there's no way of denoting when the function ends without a .. Most people seem to consider this fair but I could try to write a specific meta post here if you're concerned.

– redstarcoder – 2016-12-05T15:44:13.273

Sorry, the linked post is still relevant, but this is where I was talking about writing an answer to clear up potential ambiguities: http://meta.codegolf.stackexchange.com/questions/8737/what-even-is-a-function-by-our-standards

– redstarcoder – 2016-12-05T16:11:47.913

1@redstarcoder thanks for the info ! I feel like suffixing the ><> snippets by . would be the best way to stick to the definition of function as described in the most upvoted answer of the meta post, however I agree ; is a good alternative which requires less explanation. – Aaron – 2016-12-05T16:39:56.350

@redstarcoder nevermind using ., I just remembered it requires additional code to get the RET position on top of the stack. ; feels fair, but it also feels incorrect as per the definition of a function :-/ I'll see if I can make up my mind about it, and if I do I'll probably comment on the meta post you linked. – Aaron – 2016-12-05T16:46:41.533

4

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.

dnep

Posted 2015-12-17T19:32:46.753

Reputation: 301

0=Z9​​​​​​​​​ – Adám – 2016-03-03T22:24:41.100

Removed the =s, thanks. Regarding your suggestion, I avoided cell references on purpose, to make sure the formulas are independent of table contents - if Z9 contains a text, =Z9 won't return zero anymore. I decided not to assume anything about the table. – dnep – 2016-03-03T22:46:44.987

anyway, you made me loot at it again, and I realized I could at least save 1 byte by using to 0 the same logic that I used to 1... – dnep – 2016-03-03T23:06:56.770

But some languages have all variables set to 0 if they are not set to something else. In this context, I would see Excel as a language with (theoretically infinite) memory cells A1:ZZZ..:999... and no distinction between program code and data (i.e. may be self-modifying). Since each snippet is independent of the others, I assume it is in A1, and the rest of the sheet it blank. (For programs, I would have one whole statement in each cell A1, A2, etc.) – Adám – 2016-03-07T13:11:11.733

I see your point... but there is a further problem with cell references: Z9 on an empty sheet is an empty value that is converted to 0 in many cases, but may be converted to "" (empty string) if used in some expressions - much like a VBA uninitialized Variant - so it is not strictly equivalent to 0. For example, = 0&"a" is evaluated to "0a" but = Z9&"a" evaluates to "a". This can be solved, however by adding an unary - to the reference (thus forcing it to be numeric - again, just like in VBA). So -Z9 can be used as zero. I've just updated the answer. Thanks again. – dnep – 2016-03-07T14:08:05.157

42=ROW(Z42)​​ – Adám – 2016-03-07T14:16:39.747

Hahahahah now this looks like cheating... – dnep – 2016-03-07T14:17:43.047

How is that any more cheating than 9=9:_ in J? – Adám – 2016-03-07T14:18:23.847

And the default is numeric (evidenced by Excel right-justifying the 0 of =Z9), so you really don't need the -. – Adám – 2016-03-07T14:22:05.007

I suppose it isn't, but for me it would spoil the fun (much like using all those constants in VBA) - I could post something like that in a separate answer (like I did with VBA), but I don't feel like doing it... About the minus sign, it just wont work inside any formula, so I think it's better with the -... Think of these as self-imposed constraints! – dnep – 2016-03-07T14:28:52.700

4

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

acrolith

Posted 2015-12-17T19:32:46.753

Reputation: 3 728

1 is more stack-clean than Yx, X can be used instead of º here (it defaults to 1, º means len(stack)>1, so it does not default to anything). Also, your bytecount is 24, not 35 (CP-1252, newlines do not count if they are separate snippets). – Erik the Outgolfer – 2016-12-04T20:40:05.900

I know it wasn't possible yet at the time you posted this, but 6 can be ₆t now (push 36, square-root) to save a byte (Try it online).

– Kevin Cruijssen – 2019-03-29T10:40:50.323

3

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 0 when converted to int, except when it matches /^[0-9.]+/

aross

Posted 2015-12-17T19:32:46.753

Reputation: 1 583

3

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.

ASCIIThenANSI

Posted 2015-12-17T19:32:46.753

Reputation: 1 935

6Those sure look like literals to me. Also, don't post code that you haven't tested. – Mego – 2015-12-17T22:14:46.460

2Can you explain how they work? – Adám – 2015-12-18T03:22:44.543

@NBZ D1ffe7e45e works based on the difference between two hexadecimal numbers. That difference is then interpreted into a command. For example, the difference between 0 and 2 is 2, which is interpreted as the increment command (like + in Brainf**k). I thought that since they're being used as commands and not number literals it still counted. I'll delete the answer if it doesn't. – ASCIIThenANSI – 2015-12-18T15:22:03.670

@Mego I got the interpreter working and my code works. See the above comment for why I think they're not literals. – ASCIIThenANSI – 2015-12-18T15:39:55.560

1I don't think any of these are literals. However, I don't think you should print the numbers, since the result of each snippet must result in an actual number that can be used for further calculations. – Dennis – 2015-12-18T15:40:32.667

@Dennis Since the number is stored in the cells, should I just remove the command to print the numbers? – ASCIIThenANSI – 2015-12-18T15:41:29.240

I guess. That's what the Brainfuck answer does. – Dennis – 2015-12-18T15:43:13.310

@Dennis OK. Also, D1ffe7e45e assumes there is a 0 at the start of each program. Can I remove the 0s from the start of my snippets? – ASCIIThenANSI – 2015-12-18T15:46:57.693

I don't know. I think you should ask the OP. – Dennis – 2015-12-18T15:48:22.160

3

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!

lirtosiast

Posted 2015-12-17T19:32:46.753

Reputation: 20 331

User Mimarik suggested saving a byte on 42 with yhyT. (I rejected the edit as per http://meta.codegolf.stackexchange.com/questions/1615/suggested-edits-reject-golfing/1619#1619)

– Martin Ender – 2015-12-20T12:09:13.900

3

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.

lirtosiast

Posted 2015-12-17T19:32:46.753

Reputation: 20 331

Finally ;-) But you can do way better than that if you use full-fledged Dyalog APL. If you don't have one, it is easy to get.

– Adám – 2015-12-20T03:14:27.280

I already had Dyalog, but I didn't know there were so many system constants! – lirtosiast – 2015-12-20T19:54:10.247

⎕WX is a similar to ⎕ML; it controls the level of reserved-ness for names that are properties etc. of GUI objects. ⎕FR switches floats between 64 and 128 bit representation. ⎕AI is (UserName, CPUtime, SessionLength, KeyingTime. – Adám – 2015-12-21T02:16:31.103

Better, but you are forgetting to think arrays! E.g. 0 and 1 can each be written with only two chars... – Adám – 2015-12-21T02:18:29.210

20=⍴⍬ 1=≢# 2=⍴⍬⍬ ... 42=⍎⌽⍕⌈*○≢# – Adám – 2015-12-31T18:29:01.670

I would upvote, but @lirtosiast hasn't updated to use Nᴮᶻ's suggestions. – mbomb007 – 2016-03-03T16:23:33.827

I agree with everything except ⎕PW which is not a constant with a fixed default. I believe in recent versions of Dyalog APL, it defaults to "as wide as your session is" (and it also tracks the width of the session), and so it depends on unpredictable external factors. Also I'd be wary of blindly using ⎕WX given that that also has a default that has changed over the years, if my memory serves me well. – lstefano – 2016-06-28T13:07:29.587

3

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

mchen

Posted 2015-12-17T19:32:46.753

Reputation: 131

3

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

Argenis García

Posted 2015-12-17T19:32:46.753

Reputation: 223

3

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

anatolyg

Posted 2015-12-17T19:32:46.753

Reputation: 10 719

3

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.

dnep

Posted 2015-12-17T19:32:46.753

Reputation: 301

Interesting choice. Maybe try Excel too? – Adám – 2016-03-02T20:55:00.930

Just did it! Thanks. – dnep – 2016-03-03T21:43:52.470

3

Jelly, 31

<blank>
‘
‘‘
‘‘‘
‘‘²
‘‘²‘
‘‘‘Ḥ
⁴H’
⁴H
‘‘‘²
⁵
⁴Ḥ⁵+

Explanation

0: Outputs 0 by default

  1. Increment
  2. Increment twice
  3. Increment thrice
  4. Increment twice and square
  5. Increment twice, square, and increment
  6. Increment thrice and double
  7. Halve sixteen and decrement
  8. Halve sixteen
  9. Increment thrice and square
  10. Ten

42: Double sixteen and add ten

ASCII-only

Posted 2015-12-17T19:32:46.753

Reputation: 4 687

I thought Jelly could do better. Are there no constants for 1 - 10? – Adám – 2016-03-03T12:06:22.180

@Nᴮᶻ No. It only has constants for 256, 16, 10, space, and newline. – ASCII-only – 2016-03-03T12:07:40.927

You may want to add that the empty program produces 0. – ETHproductions – 2016-03-06T21:49:08.003

3

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

Saved 3 bytes thanks to nimi and 3 bytes thanks to xnor.

Laikoni

Posted 2015-12-17T19:32:46.753

Reputation: 23 676

Save two bytes with 6: length$show[True]. 10: length$show[LT ..]. – nimi – 2016-08-25T20:45:51.853

42: fromEnum$succ$last$show(). – nimi – 2016-08-25T22:34:18.007

sum[] gets you 0 – xnor – 2016-08-25T23:09:03.257

2

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 :)

user41805

Posted 2015-12-17T19:32:46.753

Reputation: 16 320

2

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).

phase

Posted 2015-12-17T19:32:46.753

Reputation: 2 540

Could you may explain what happens here? – Adám – 2015-12-18T14:37:30.377

@NBZ voila, good sir – phase – 2015-12-18T15:13:26.033

2If A through F are hex values, are they not numeric literals then? – Adám – 2015-12-21T14:06:36.600

2

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)).

Try it out here!

Thomas Kwa has golfed a superior solution.

p1xel

Posted 2015-12-17T19:32:46.753

Reputation: 241

I would suggest 1) adding an explanation for what these do, and 2) adding a link to your code in the Pyth online interpreter, like so.

– El'endia Starman – 2015-12-18T07:22:14.950

y can be used to double the value of a number, for example, you can get 42 with yhyT which is like double(add_one(double(ten))) – FryAmTheEggman – 2015-12-18T15:07:14.623

The loop is completely useless. Aside from the solution yhyT you could simply do hh*ThhhhZ. – Jakube – 2015-12-19T15:30:40.127

2

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)

Qwertiy

Posted 2015-12-17T19:32:46.753

Reputation: 2 697

2

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

Aaron Davies

Posted 2015-12-17T19:32:46.753

Reputation: 881

you're just meant to push the numbers for use, you needn't print them. – cat – 2015-12-19T12:52:10.670

Ah. The \x forms may still be invalid for a different reason then: for technical reasons, you can't actually use their return value for anything—to do that, you have to use a different form, ."\\x" (which wouldn't be any use here as it's six characters long). – Aaron Davies – 2015-12-21T06:40:23.220

2

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

Khaled.K

Posted 2015-12-17T19:32:46.753

Reputation: 1 435

@NBZ fixed the byte counts, I also assume that I cannot print 4 and 2 to produce 42, it has to be the value 42 – Khaled.K – 2015-12-21T09:44:11.960

@KhaledAKhunaifer: You can do calculations inside enum{} like enum{z,o,t,e=t<<t} // e=8... – None – 2015-12-21T10:16:00.587

@yeti tip taken into account, also 3<<4 is 48 which is '0', useful to convert digits into ascii characters – Khaled.K – 2015-12-21T11:06:50.723

2

, 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.))

Mama Fun Roll

Posted 2015-12-17T19:32:46.753

Reputation: 7 234

It's nice being on top, but assuming ESMin is eligible for winning, why isn't this accepted? – cat – 2016-03-01T01:30:54.910

Look at the byte count. (If you're looking at the leaderboard, it's buggy for ESMin.) – Mama Fun Roll – 2016-03-01T02:40:59.317

1Oh, yeah, I totally know how to read. – cat – 2016-03-01T02:42:27.377

@ӍѲꝆΛҐӍΛПҒЦꝆ, I don't see a leaderboard in this question (though many a [tag:code-golf] question does have one). Am I missing something (like, perhaps, a userscript that adds a leaderboard to every [tag:code-golf] question that doesn't have one already)? – msh210 – 2016-03-01T22:45:30.997

1If you have the PPCG userscript, you will see the board. – Mama Fun Roll – 2016-03-02T02:45:27.027

2

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

Conor O'Brien

Posted 2015-12-17T19:32:46.753

Reputation: 36 228

1That's really neat. – Adám – 2016-03-01T20:31:35.903

But then I'm using the literal 7 at the end. – Conor O'Brien – 2016-03-01T21:56:32.310

@Nᴮᶻ Ah, nice! I was wondering how to use pi times! – Conor O'Brien – 2016-03-01T22:33:04.203

If you found this challenge fun, you may want go submit a J answer here...

– Adám – 2016-03-01T22:38:17.650

@Nᴮᶻ Thank you! I am doing that now! :D – Conor O'Brien – 2016-03-01T22:40:06.173

16 squared plus 6: (*:+])6:_ – Adám – 2016-03-01T22:42:04.043

#C.>.%:^@^2:_ (you can remove the @) is the count (42) of the permutations (0...41) of ceiling of e^e^2. – Adám – 2016-03-01T22:48:35.887

I actually had J in mind when I wrote *Note that the above rules may prevent some languages from participating, even if they are Turing complete.

  • in the OP!
  • < – Adám – 2016-03-03T13:05:07.800

1Another alternative for 42: 7 squared minus 7 (*:-])7:_ – M L – 2016-03-11T22:43:57.237

I thought we can't use numbers? @Adám – Leaky Nun – 2016-08-23T05:05:25.930

1@LeakyNun 7:_ is a function, which just happens to have a digit in its name. Here, it takes infinity (_) as argument, and returns seven. There is no function called 17:. Compare to TI-BASIC's 10^( which is a single-byte function with a funny name. – Adám – 2016-08-23T06:08:14.003

2

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.

Hotkeys

Posted 2015-12-17T19:32:46.753

Reputation: 1 015

2

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.

dnep

Posted 2015-12-17T19:32:46.753

Reputation: 301

2

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.

RenderSettings

Posted 2015-12-17T19:32:46.753

Reputation: 620

8, 9, 42: Wouldn't that be literal numbers? – Adám – 2016-03-03T12:04:33.250

Nope. They aren't literals, you can't cast them to numbers. If you ran +1 in the Hoon repl, it evaluates to the value at the top of the context the same way that - does. The only reason I'm able to get the number out of it is by compiling the code to the equivalent of Assembly and pulling the axis out of the formula. – RenderSettings – 2016-03-04T14:52:21.623

I still think this is questionable. Can you get any number with the incantation +:!=(+​…)? – Adám – 2016-03-07T13:16:34.807

Yes, the same way that you can get any number by pulling the index that -<- snippets compile to. Think of it more as compiling C "a=1; &a" and grabbing the index the mov is pulling from. Since all Hoon compiles down to (Nock)[https://github.com/urbit/urbit/blob/master/Spec/nock/5.txt], which is entirely based on tree indicies and a state machine over natural numbers, I think it's perfectly fine to grab numbers from the output. I could change it back to tree navigation syntax for 8/9/42, but it's the exact same emitted Nock code and means the same thing. It's just marginally shorter for them. – RenderSettings – 2016-03-07T18:42:29.840

I think literal tree navigation would be more in the spirit of the OP. Otherwise, one could argue that 10 should be valid, because ceil(square(pi())) would evaluate to 10 anyway. – Adám – 2016-03-07T18:50:42.270

+10 does not evaluate to 10. It's evaluating to the value at index 10 in the context, which is most of the Arvo kernel and the entire stdlib. The != rune just doesn't evaluate it, but compiles it to Nock instead which can be indexed as a noun. The analogy would be more against using π instead of pi - they mean the same thing, do the same thing, compile to the same thing. Regardless, I'll change them back to tree navigation syntax. – RenderSettings – 2016-03-07T18:58:24.370

2

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[(),(),(),(),(),(),()]

HEGX64

Posted 2015-12-17T19:32:46.753

Reputation: 313

2

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.

Laterow

Posted 2015-12-17T19:32:46.753

Reputation: 161

2

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.

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.

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.

Conor O'Brien

Posted 2015-12-17T19:32:46.753

Reputation: 36 228

Why is there a built in for 42? – Cyoce – 2016-08-26T21:12:02.500

@Cyoce "Okay, so I have a 42-builtin. I'm obsessed with that number" ;) – Conor O'Brien – 2016-08-26T21:33:19.440

2

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

Paul Chernoch

Posted 2015-12-17T19:32:46.753

Reputation: 249

2

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

bb94

Posted 2015-12-17T19:32:46.753

Reputation: 1 831

2

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

Sefa

Posted 2015-12-17T19:32:46.753

Reputation: 582

Can't you mix operations like + and *? – Adám – 2016-08-26T14:07:53.133

I don't think so sadly, the only one where it could be useful is 7 and it need +4 for parenthesis to only remove 3 (the last +$A) – Sefa – 2016-08-26T14:32:29.097

2

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

rnso

Posted 2015-12-17T19:32:46.753

Reputation: 1 635

2

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

Angs

Posted 2015-12-17T19:32:46.753

Reputation: 4 825

1

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

12Me21

Posted 2015-12-17T19:32:46.753

Reputation: 6 110

What does the ? do? – Adám – 2017-02-11T21:31:33.527

How about 42: #BQLSF*#BQPEQ? – Adám – 2017-02-11T21:32:43.847

? is a shortcut for PRINT, and I just realized this isn't required. – 12Me21 – 2017-02-11T21:45:26.130

1

tcl, 376

$argc
incr i
llength [list {} {}]
llength [list {} {} {}]
llength [list {} {} {} {}]
llength [list {} {} {} {} {}]
llength [list {} {} {} {} {} {}]
llength [list {} {} {} {} {} {} {}]
llength [list {} {} {} {} {} {} {} {}]
llength [list {} {} {} {} {} {} {} {} {}]
llength [list {} {} {} {} {} {} {} {} {} {}]
expr [llength [list {} {} {} {} {} {} {}]]*[llength [list {} {} {} {} {} {}]]

To try it, on the first line just prepend puts and in the others wrap them by puts [ before and ] after.

demo

sergiol

Posted 2015-12-17T19:32:46.753

Reputation: 3 055

Can't you use two such things and e.g. multiply them? – Adám – 2017-02-12T10:22:03.493

@Adám: I've got your point. Thanks! – sergiol – 2017-02-12T13:07:26.063

It would seem to me that puts [...] isn't necessary for further computation. – Adám – 2017-02-12T15:54:10.493

@Adám: changed according to your observation. – sergiol – 2017-02-12T16:26:13.807

1

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:

  1. This is a short-hand of 0.0
  2. Not zero is 1, this is two keystrokes (so two bytes), which is shorter then PI/PI (three keystrokes)
  3. ** 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

Shaun Bebbers

Posted 2015-12-17T19:32:46.753

Reputation: 1 814

1You don't need PRINTs. You use a lot of forbidden strings, no? graphice should probably be with an S. – Adám – 2017-02-14T17:47:25.787

Good spot - thanks. I'll correct the typo. I put it as a program to run so that I could see each outputted number, rather than running everything in direct mode for each entry. – Shaun Bebbers – 2017-02-14T17:48:36.200

I also used LET A$="...." simply because I wanted to do something different than using PI - if it's not allowed then my bad. – Shaun Bebbers – 2017-02-14T17:51:00.050

Amended version is now up - I'll work out how to get 42 later. – Shaun Bebbers – 2017-02-15T10:17:06.947

Why not (PI+PI)*((PI+PI)+((PI/PI)))? Do you really need doubly nested parens in 7? Is there no order of execution for number 5? Why does 4 have parens after INT, but number 5 doesn't? – Adám – 2017-02-15T10:19:55.823

Yes you can remove one set of brackets from ((PI/PI)) - I did it to make it clearer to me. Line 4 PRINT INT (SGN PI+PI) - if you PRINT INT SGN PI+PI you will get a different result. It's been a while since I've delved into Sinclair ZX81 BASIC but there are some rounding errors with PI - also brackets are not always required when calling INT, RND and other functions like other BASIC variants. It was quirky, heavily cost-reduced home computer with only 8K ROM so sometimes you'll get unexpected results. – Shaun Bebbers – 2017-02-15T10:25:58.503

1This is [tag:code-golf]. You've got to strip it down to the very bare minimum, (ab)using quirks. Clarity is not a consideration ;-) – Adám – 2017-02-15T10:27:39.030

1It is common to include code-golf solutions twice in answer posts. First the actual golfed submission, then an "un-golfed" one for clarity. Also, you're missing 0, and 1 should be PI/PI, no? May I edit your post? – Adám – 2017-02-15T10:30:43.360

Yes I will - trying to write this even into a ZX81 emulator was slightly frustrating so it brought out some malevolence in me (hoping that someone else will try to type it in) - I'll properly golf it later when I'm in a happier mood. Probably. – Shaun Bebbers – 2017-02-15T10:31:07.420

I'm pretty sure PRINT NOT PI will give you zero – Shaun Bebbers – 2017-02-15T10:32:09.450

But PI-PI is shorter than NOT PI. Also, remember that PRINT should not be in the actual submission. – Adám – 2017-02-15T10:33:44.587

It depends whether you are counting bytes or characters. PI is one keystroke on the ZX81, so 1 byte, NOT PI is two keystrokes, so two bytes, PI-PI is three bytes. NOT PI is therefore shorter than PI-PI in the ZX81 byte count. – Shaun Bebbers – 2017-02-15T10:35:38.730

Usually, tokenized languages are counted by their actual internal representation. See e.g. http://meta.codegolf.stackexchange.com/questions/1541/how-to-score-ti-basic

– Adám – 2017-02-15T10:37:05.937

Actually, I've just remembered that you can PRINT . which is zero (same as PRINT 0.0) – Shaun Bebbers – 2017-02-15T10:51:40.557

You still have superfluous parens. – Adám – 2017-02-15T12:06:21.533

Looking good, but do you really need all the spaces, e.g. + COS? – Adám – 2017-02-15T13:17:38.803

The spaces are generated by the ZX81 interpreter. If you enter 10PRINT"HELLO", you will see 10 PRINT "HELLO" on screen. This is the infamous '1-key' entry system that Sinclair came up with, although entering PI takes four key presses in total, ie, shift and new line to get to the function mode, and then shift and M to produce PI – Shaun Bebbers – 2017-02-15T13:27:12.293

1

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.

IDid

Posted 2015-12-17T19:32:46.753

Reputation: 101

1

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

Try it online: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42

Bubbler

Posted 2015-12-17T19:32:46.753

Reputation: 16 616

1

MathGolf, 20 bytes

p   # 0
î   # 1
⌠   # 2
d±  # 3
☻√  # 4
♂½  # 5
B½  # 6
D½  # 7
☻½  # 8
d²  # 9
♂   # 10
J∞  # 42

Try it online.

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; ; ; ; ; ; etc. (Try it online).

Kevin Cruijssen

Posted 2015-12-17T19:32:46.753

Reputation: 67 575

1

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.

Digital Trauma

Posted 2015-12-17T19:32:46.753

Reputation: 64 644

1"Make 12 snippets/expressions..." - I don't think the print command counts in "snippet length". – None – 2015-12-17T21:57:30.870

@yeti yes, I see. Oh well, looks like you have me beat handily anyway. – Digital Trauma – 2015-12-17T22:01:10.123

I started without using A...F and then saw your comment about A...F. So your solution influenced mine.... e.g.: 42 was IIZd+*dZ+ initially... – None – 2015-12-17T22:02:54.170

Can A F be used as part of a single number, or only stand-alone? – Adám – 2015-12-21T14:11:49.567

I believe that E and F here are digits (even when they are greater than the input radix). Evidence for this is that they combine as digits; e.g. F0 -> 150. You can see the same behaviour with decimal digits once you change input and output radix. – Toby Speight – 2016-03-02T09:27:50.833

@TobySpeight Yep - probably a fair point – Digital Trauma – 2016-03-05T00:49:31.610

1

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.

M L

Posted 2015-12-17T19:32:46.753

Reputation: 2 865

1

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

M L

Posted 2015-12-17T19:32:46.753

Reputation: 2 865

1

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

M L

Posted 2015-12-17T19:32:46.753

Reputation: 2 865

1

Actually, 32 bytes (non-competing)

╜
╒K
 ⌐
╦L
╦K
╦L⌐
╦Lτ
╠²L
╦L╙
╦L²
kY╤
╒º╦+L

All full programs. Try it online!

Explanation

  • is ln(2)
  • is pi
  • is e
  • L is floor
  • K is ceil
  • τ is double
  • ² is square

For the last one:

╒º╦+L
╒      ln(2)
 º     convert from radian to degree (39.71440802747729)
  ╦+   + pi (42.85600068106709)
    L  floor

Leaky Nun

Posted 2015-12-17T19:32:46.753

Reputation: 45 011

Why non-competing? – Adám – 2016-08-23T07:20:49.143

1@Adám Because Actually is released this year? – Leaky Nun – 2016-08-23T07:23:18.827

I see. Move along. – Adám – 2016-08-23T07:28:05.543

@LeakyNun Actually, Actually seems to be started in november 2015 looking at the github graph. I'm not sure when the 'official' release date was, though, so you could be right. Just wanted to use 'Actually, Actually..` Love that programming language's name. ;P

– Kevin Cruijssen – 2016-08-23T07:40:13.450

@KevinCruijssen Actually and seriously, Seriously should be the one released in Sep 2015. – Leaky Nun – 2016-08-23T07:41:30.340

@KevinCruijssen When I am home I will download the version on Dec 17 2015 and then make this competing – Leaky Nun – 2016-08-23T07:50:03.270

Well, the whole discussion is unnecessary now... ;)

– DLosc – 2017-12-16T19:39:47.840

1

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.)

Erik the Outgolfer

Posted 2015-12-17T19:32:46.753

Reputation: 38 134

1

Brain-Flak, 172 143 bytes (non-competing)

(<>)
(())
(()())
(()()())
(()()()())
(()()()()())
((()()()){})
((()()()){}())
((()()()()){})
(((()()())){}{})
((()()()()()){})
(((((()()()){}()){})){}{})

Try it online! (copy-paste yourself)

Erik the Outgolfer

Posted 2015-12-17T19:32:46.753

Reputation: 38 134

1

QBIC, 14 bytes (non-competing)

Thank you @Adám, for clarifying part of the rules. Brought the byecount down to 14.

This one's easy in QBIC, but marked non-competing because (this part of) QBIC was made after the challenge was posted.

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.

steenbergh

Posted 2015-12-17T19:32:46.753

Reputation: 7 772

1Save 11 bytes by removing the question-marks, as per the FAQ: *Q Do I need to print the result of each snippet? A No, making the result available for subsequent use is enough.* – Adám – 2016-10-26T09:24:24.130

You can still take them out and include your byte count (14). And you were not going to win anyway, as there is already a 13-byte answer. – Adám – 2016-10-26T09:27:12.653

0

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

G B

Posted 2015-12-17T19:32:46.753

Reputation: 11 099

Can you maybe provide an explanation? – Adám – 2017-02-15T12:05:11.523

0

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

Taylor Scott

Posted 2015-12-17T19:32:46.753

Reputation: 6 709

0

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.

Unrelated String

Posted 2015-12-17T19:32:46.753

Reputation: 5 300

0

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

TIO code to evaluate all of these at once

Benjamin Urquhart

Posted 2015-12-17T19:32:46.753

Reputation: 1 262

0

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

Leaky Nun

Posted 2015-12-17T19:32:46.753

Reputation: 45 011

Why wouldn't they be valid? – Adám – 2016-08-22T18:51:28.850

@Adám Because a "snippet" is hard to define? – Leaky Nun – 2016-08-22T19:21:41.550

That was meant as a relaxation of rules, not a stringency. I don't know C, but can't you remove main(a){ and ;}? – Adám – 2016-08-22T20:03:38.707

@Adám I'm not sure. – Leaky Nun – 2016-08-22T20:09:08.807

@Adám Given that the a defaults to 1 because it is the argument of main and the name does not have to be a, do you think I can remove the boilerplate? For example, main(c){c=++c+c++;++c*c++;} works as well. – Leaky Nun – 2016-08-22T20:31:16.583

Yes, I do. If a (or c for that matter) hasn't been used yet (which is a kind of "default"), then the snippet will evaluate to the desired number. Ergo, remove the boilerplates. – Adám – 2016-08-22T22:25:57.723

@Adám Then can the enum boilerplate in the above solution be removed also?

– Leaky Nun – 2016-08-23T03:56:28.063

I'm not sure what it does there. – Adám – 2016-08-23T06:15:37.050

@Adám Well, I believe that in an enum, the first variable would be 0, etc. – Leaky Nun – 2016-08-23T06:38:53.023

Then it is needed to get the final result, no? – Adám – 2016-08-23T07:02:42.180

@Adám Well, so is main(a), no? – Leaky Nun – 2016-08-23T07:16:30.020

Let us continue this discussion in chat.

– Adám – 2016-08-23T07:18:30.360