Time for another casual little challenge.
For this one there are only 2 rules:
- you must add numbers
a
andb
together - you must NOT use the
+-*/
operators
Apart from that there are no more rules, and can be done with any language you want!
Pseudocode:
a = 2
b = 32
add(a, b) => 34
Test:
add(a, b) == a + b
Have fun! Let's see what you come up with!
Latest comments (30)
Crystal or Ruby
js
Dangerous one:
A bit shorter (if you don't mind polluting namespace):
Here's another, more serious, attempt (still in Ruby) :
Some explanations : in Ruby
0..10
is called a range. It is really useful to make arbitrary loops or splice an array, for example. Simply, a range is a suite of values. The syntax I used here is0...10
(note the three dots) which is an exclusive range : the suite of values goes from0
to9
. So the trick is to have a range going from-a
tob
and excludingb
because0
is included in the suite.In python
Nice cheat :p
Thank you for the challenge, I finally got into WebAssembly 🎉
I spent an unfortunate amount of time on this...
Output:
This currently only works on unsigned integers. I don't feel like spending the time now to remember how two's complement works.
Though I guess I'll be a bit more pedantic with this one:
for i in 0..32
smuggles in some integer addition. So here's the set theoretic implementation, which has—less reliance on plus signs:Output:
Z means zero, and S means increment. So this is zero incremented eight times.
It kinda is nasty 🤣 I like it though