Skip to main content
added print since REPL cannot be assumed.
Source Link
Bassem
  • 201
  • 1
  • 6

Python 2.7 – 2934*

Oh how much this first one sucks. Pretty ugly, this one is. 63 chars.

''print''.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.

''print''.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.

''print''.join([str(1-int(x)) for x in '']) 

Since join() takes a generator the brackets can be removed. 32 chars.

''print''.join(str(1-int(x))for x in'') 

And backticks can be used instead of str()

''print''.join(`1-int(x)`for x in'') 

Reduced to 44 from 2934 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the above.

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.

Python 2.7 – 34*

Oh how much this first one sucks. Pretty ugly, this one is. 63 chars.

print''.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.

print''.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.

print''.join([str(1-int(x)) for x in '']) 

Since join() takes a generator the brackets can be removed. 32 chars.

print''.join(str(1-int(x))for x in'') 

And backticks can be used instead of str()

print''.join(`1-int(x)`for x in'') 

Reduced to 44 from 34 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the above.

reduced size
Source Link
Bassem
  • 201
  • 1
  • 6

Python 2.7 – 3429

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 '']) 
''.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 '']) 
''.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 '']) 
''.join([str(1-int(x)) for x in '']) 

Since join()join() takes a generator the brackets can be removed. 32 chars.

''.join(str(1-int(x))for x in'') 
''.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 3229 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int)bin(-int) returns -0bxxx hence the tricks above.

Python 2.7 – 34

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'') 

Reduced to 44 from 32 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the tricks above.

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.

reduced size
Source Link
Bassem
  • 201
  • 1
  • 6

Python 2.7 – 34

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. 3432 chars.

''.join(str(1-int(x)) for x in ''in'') 

Reduced to 44 from 3432 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the tricks above.

Python 2.7 – 34

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. 34 chars.

''.join(str(1-int(x)) for x in '') 

Reduced to 44 from 34 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the tricks above.

Python 2.7 – 34

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'') 

Reduced to 44 from 32 thanks to pointers from @TheRare

Finding one's complement is difficult in python since bin(-int) returns -0bxxx hence the tricks above.

added 277 characters in body
Source Link
Bassem
  • 201
  • 1
  • 6
Loading
Reduced to 44 from 50 thanks to a comment from @TheRare
Source Link
Bassem
  • 201
  • 1
  • 6
Loading
fix formatting
Source Link
user16402
user16402
Loading
added 3 characters in body
Source Link
Bassem
  • 201
  • 1
  • 6
Loading
deleted 8 characters in body
Source Link
Bassem
  • 201
  • 1
  • 6
Loading
Source Link
Bassem
  • 201
  • 1
  • 6
Loading