Skip to main content
More elegant version added
Source Link
avall
  • 1.6k
  • 1
  • 10
  • 17

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 
def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Edit: Here's alternative version which adds integers, not stringified twos.

def int(a): return ~eval(`a`) def add(a,b): return int(a)+int(b) print ~add(2,2) 

Tilde is an unary inverse operator which returns -x-1, so first step is to get -6 and then with another operator in print function get 5

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Tilde is an unary inverse operator which returns -x-1, so first step is to get -6 and then with another operator in print function get 5

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Edit: Here's alternative version which adds integers, not stringified twos.

def int(a): return ~eval(`a`) def add(a,b): return int(a)+int(b) print ~add(2,2) 

Tilde is an unary inverse operator which returns -x-1, so first step is to get -6 and then with another operator in print function get 5

explanation added
Source Link
avall
  • 1.6k
  • 1
  • 10
  • 17

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Tilde is an unary inverse operator which returns -x-1, so first step is to get -6 and then with another operator in print function get 5

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2") 

Tilde is an unary inverse operator which returns -x-1, so first step is to get -6 and then with another operator in print function get 5

Source Link
avall
  • 1.6k
  • 1
  • 10
  • 17

Python

Code prints 5 which is correct answer for this task.

def int(a): return ~eval(a) def add(a,b): return int(a)+int(b) print ~add("2","2")