Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I couldn't resist.

    add = lambda a, b: add(a ^ b, (a & b) << 1) if b else a


And if you need to handle negatives:

    def add(a, b):
        while a and b:
            if a ^ b < 0: (a, b) = (a & ~b, b & ~a)
            (a, b) = (a ^ b, (a & b) << 1)
        return a or b




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: