5

Write a function that adds two numbers together. However, do not use + or any arithmetic operations to do so.

Comments
  • 6
    function writeABetterUserStoryNextTime() {
    $a = 10;
    $b = 20;

    print ('Not sure that ' . $a . $b . ' is what the customer had in mind, but the user story did not give all details of the expected feature.');
  • 0
    function addTwoNumbersTogether(list) {
    list.push('two numbers together');
    }
  • 9
    function sum(int a, int b){
    return 3;
    }
    sum(1, 2); // Returns 3
  • 0
    Now the real answer:
    (JavaScript)

    function sum(a, b){
    var arr = [a, b];
    return arr.sum();
    }
    sum(1, 2); // Returns 3
    sum(3, 4); // Returns 7

    Easy af.
  • 0
    @Letmecode yup binary and some code to simulate the address circuit would do it
  • 6
    def sum(a, b):
    if a == 0:
    return b
    elif b == 0:
    return a
    elif a == 1:
    if b == 1:
    return 2
    if b == 2:
    return 3
    if b == 3:
    return 3
    # etc
    elif a == 2:
    if b == 1:
    return 3
    if b == 2:
    return 4
    if b == 3:
    return 5
    # etc
    And so on, with negative numbers. It's a bit long but I can create a function that would write this function ;)
  • 1
    @Joserc87 not without an iterator which would require the incremental operator
  • 0
    @Joserc87 "reflection" would be the keyword in that case^^
  • 1
    @TheAnimatrix but there it would be valid, since it's just the code that generates the code. Right? Or else I could generate code that generates code that generates code. xD
  • 1
  • 0
    I see autocorrect corrected the adder circuit above to the address circuit in my previous comment but that's what I meant, an adder circuit
  • 4
    @Skayo lmao 😂😂😂
Add Comment