Python 2.7 – 29
Oh how much this first one sucks. Pretty ugly, this one is. 63 chars.
''.join([bin(~0)[3:] if x == '0' else bin(~1)[4:] for x in ''])
This one is a bit better but still not that fancy. 44 chars.
''.join([str(int(not(int(x)))) for x in ''])
Since int(x) and 1
returns int(x)
if it's not 0 and otherwise False. The solution can be further reduced to 36 chars.
''.join([str(1-int(x)) for x in ''])
Since join()
takes a generator the brackets can be removed. 32 chars.
''.join(str(1-int(x))for x in'')
And backticks can be used instead of str()
''.join(`1-int(x)`for x in'')
Reduced to 44 from 29 thanks to pointers from @TheRare
Finding one's complement is difficult in python since bin(-int)
returns -0bxxx hence the above.
rev
that does this, so technically all it takes is a 3-byte shell script, although I see such answers are implicitly disallowed. – David Z 6 hours ago