Live data from Hacker News

Write a program that makes 2 + 2 = 5

codegolf.stackexchange.com

21–30 of 76 posts

Re: Write a program that makes 2 + 2 = 5

#21

Here's a Ruby solution that really does modify the + operation: class Fixnum alias_method :old_plus, :+ def +(*args) old_plus(*args).old_plus(1) end end 2 + 2 #=> 5

Here is a Nimrod version which does the same:

  proc `+`(x, y: int): int =
    result = x
    result.inc(y)
    result.inc

  echo(2 + 2) # => 5

Re: Write a program that makes 2 + 2 = 5

#23
Here's mine :

    $ cat test.c
    #include 
    
    int main() {
        int a = 3;
        int b = 3;
    
        // aren't we supposed to add 2 and 2 ??/
        a = 2;
        b = 2;
    
        printf("%d\n", a + b);
    
        return 0;
    }
    $ gcc -W -Wall -trigraphs test2.c 2>/dev/null
    $ ./a.out
    5
    $

Re: Write a program that makes 2 + 2 = 5

#24

Here's a Ruby solution that really does modify the + operation: class Fixnum alias_method :old_plus, :+ def +(*args) old_plus(*args).old_plus(1) end end 2 + 2 #=> 5

Here's a ruby solution that only affects 2+2:

    class Fixnum
      alias_method :old_plus, :+
      def +(other)
        return 5 if (self == 2 && other == 2)
        old_plus(other)
      end
    end

Re: Write a program that makes 2 + 2 = 5

#28
Asking: Isn't the only true solution the one using Decibels for Addition? Because everyone else either just redefines or overwrites a value. Also addition of decibels cannot be disproofed as fake.
Post reply on HN