Skip to content

Instantly share code, notes, and snippets.

@etandel
Created July 7, 2014 14:27
Show Gist options
  • Save etandel/b9b126fbfaf9a6b80e4d to your computer and use it in GitHub Desktop.
Save etandel/b9b126fbfaf9a6b80e4d to your computer and use it in GitHub Desktop.
Desfio EQ

Python:

class Num(int):
    def __eq__(self, n):
         return True

x = Num(3)
assert(x == x + 2)

Lua:

debug.setmetatable(function () end, {
    __add = function(self) return self end
})

function x() end
assert(x == x + 2)

Moonscript:

debug.setmetatable nil,
    __add: => self

assert x == x + 2
assert a == a + 3
assert b == b + 4
assert c == c + 5

Ruby:

class MyS < String
    def +(n)
        "x + 2"
    end
end
x = MyS.new "x + 2"

raise unless x == x + 2

C:

#include <float.h>
#include <assert.h>

void treta(void){
    float x = FLT_MAX;
    assert(x == x+2);
}

C++ (Por Marcos Medeiros):

#include <iostream>
using namespace std;

class Numero {
    int val;
public:
    Numero(int n = 0) : val(n) {}
    ~Numero() {}
    const Numero operator+(int n) {
        return Numero(val);
    }
    const bool operator==(const Numero& l) {
        if (this->val == l.val)
            return true;
        return false;
    }
};

int main()
{
    Numero a = 1;
    if (a == a + 2)
        cout << "Onde esta seu deus agora?" << endl;
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment