"Write" a simple calculator without writing a single line of code

J, 7 questions/answers, none about J

echo a%b[echo a*b[echo a-b[echo a+b[b=:?2147483647 [a=:?2147483647

It's a pretty damn cheap way to do it, I'm not gonna lie. Here are the SO answers I used:

  • echo This answer

  • +, -, * and % This question

  • ? This answer

  • [ This answer

  • = and : This community wiki question

  • 2147483647 This answer

  • foo This answer

I renamed variable foo as a and b in the code.


Python 2, 7 6 references

Creating this solution wasn't as easy as it looked. Searching Stack Overflow for specific code is difficult, since symbols are not included in the search.

I had found a way to do this with 2000-bit random numbers, using a different answer in place of Ref #1, but I couldn't test it on the online environments I use since it involves getrandbits, which calls os.urandom, giving me a NotImplementedError, so I went this way instead. This could actually be used now, with TIO.

Try it online

#assumed to be loaded
import random

n1 = []
n1.append(random.randint(1, 100))

n2 = []
n2.append(random.randint(1, 100))

r1 = map(sum, zip(n1, n2))
r2 = map(lambda t: t[0] - t[1] ,zip(n1, n2))

ab = [n1[i]*n2[i] for i in range(len(n1))]

r1, last = r1[0], r1[-1]
r2, last = r2[0], r2[-1]
ab, last = ab[0], ab[-1]
n2, last = n2[0], n2[-1]

print r1
print r2
print ab
ab = float(ab) / n2
ab = float(ab) / n2
print ab

References

import random is assumed to be loaded, since the question says that's allowed.

  1. lst = [] and lst.append(random.randint(1, 100)) - Here

  2. map(sum, zip(r1, r2)), map(lambda t: t[0] - t[1] ,zip(r1, r2)), r1, and r2 - Here

  3. result = float(a) / b - Here

  4. ab = [a[i]*b[i] for i in range(len(a))] - Here

  5. first, last = some_list[0], some_list[-1] - Here

  6. print x - Here

Renamed

  1. lst renamed to n1 and n2 (Ref #1: I used the entire code twice)

  2. r1 and r2 renamed to n1 and n2 (Ref #2: I used the separate variables later though, to assign the maps and to divide in the last print, since the answer included them. )

  3. result and a renamed to ab, and b renamed to n2 (Ref #3)

  4. a and b renamed to n1 and n2 (Ref #4)

  5. first and some_list both renamed to r1, r2, ab, or n2, depending on which line. (Ref #5: I used this four times. Note that only the first assignment is used, so I don't rename last)

  6. x is renamed to r1, r2, or ab, depending on which line. (Ref #6)