Add two numbers
Minecraft 1.10, 221 characters (non-competing)
See, this is what we have to deal with when we make Minecraft maps.
Aside: There's no way to take a string input in Minecraft, so I'm cheating a bit by making you input the numbers into the program itself. (It's somewhat justifiable because quite a few maps, like Lorgon111's Minecraft Bingo, require you to copy and paste commands into chat in order to input a number.)
Thank you abrightmoore for the Block Labels MCEdit filter.
scoreboard objectives add a dummy
scoreboard players set m a 6
scoreboard players set n a 8
scoreboard players operation r a += m a
scoreboard players operation r a += n a
tellraw @a {"score":{"name":"r","objective":"a"}}
Non-competing due to difficulties in input, and I have no idea how to count bytes in this thing (the blytes system is flawed for command blocks).
Jelly, 1 byte
+
Try it online!
Also works in 05AB1E, Actually, APL, Braingolf, ,,, (Commata), Factor, Forth, Implicit, J, Julia, K, kdb+, Keg, Ly, MathGolf, MATL, Pyke, Deorst, and Q.
Binary lambda calculus, 4.125 bytes
Input and output as Church numerals.
00000000 01011111 01100101 11101101 0
In lambda calculus, it is λm. λn. λf. λx. m f (n f x).
De Bruijn index: λ λ λ λ 4 2 (3 2 1)
Lambda calculus is a concise way of describing a mapping (function).
For example, this task can be written as λx. λy. x + y
The thing to note is, that this is not a lambda (function) which takes two arguments. This is actually a nested lambda. However, it behaves like a lambda which takes two arguments, so it can be informally described as such. Every lambda formally only takes one argument.
For example, if we apply this lambda to 3 and 4:
(λx. λy. x + y) 3 4 ≡ (λy. 3 + y) 4 ≡ 3 + 4 = 7
So, the first lambda actually returns another lambda.
Church numerals is a way of doing away with the extra signs, leaving with only lambda symbols and variables.
Each number in the Church system is actually a lambda that specifies how many times the function is applied to an item.
Let the function be f and the item be x.
So, the number 1 would correspond to λf. λx. f x, which means apply f to x exactly once.
The number 3, for example, would be λf. λx. f (f (f x)), which means apply f to x exactly three times.
Therefore, to add two Church numerals (say, m and n) together, it is the same as applying f to x, m + n times.
We can observe that this is the same as first applying f to x, n times, and then applying f to the resulting item m times.
For example, 2 would mean f(f(x))
and 3 would mean f(f(f(x)))
, so 2 + 3 would be f(f(f(f(f(x)))))
.
To apply f to x, n times, we have n f x.
You can view m and n as functions taking two arguments, informally.
Then, we apply f again to this resulting item, m times: m f (n f x).
Then, we add back the boilerplate to obtain λm. λn. λf. λx. m f (n f x).
Now, we have to convert it to De Bruijn index.
Firstly, we count the "relative distance" between each variable to the lambda declaration. For example, the m would have a distance of 4, because it is declared 4 lambdas "ago". Similarly, the n would have a distance of 3, the f would have a distance of 2, and the x would have a distance of 1.
So, we write it as this intermediate form: λm. λn. λf. λx. 4 2 (3 2 1)
Then, we remove the variable declarations, leaving us with: λ λ λ λ 4 2 (3 2 1)
Now, we convert it to binary lambda calculus.
The rules are:
- λ becomes
00
. - m n (grouping) becomes
01 m n
. - numbers i becomes
1
i times +0
, for example 4 becomes11110
.
λ λ λ λ 4 2 (3 2 1)
≡ λ λ λ λ 11110
110
(1110
110
10
)
≡ λ λ λ λ 11110
110
0101 111011010
≡ λ λ λ λ 0101
111101100101111011010
≡ 00
00
00
00
0101
111101100101 111011010
≡ 000000000101111101100101111011010