Skip to content

Instantly share code, notes, and snippets.

@csarn
Created April 28, 2016 15:57
Show Gist options
  • Save csarn/8ee806d949316fb258eddfd6065eafc8 to your computer and use it in GitHub Desktop.
Save csarn/8ee806d949316fb258eddfd6065eafc8 to your computer and use it in GitHub Desktop.
# solution to https://technology.jana.com/2016/04/26/challenge-your-python-knowledge/
# puzzle 4, in the original version (with the typo)
# replacing __repr__ without typing double underscores
# selected deque, because it has a method (pop) that
# 1) has no arguments
# 2) modifies the object
# 3) can return a string
from ctypes import *
from collections import deque
import sys
ptr_size = sizeof(c_void_p)
a = c_void_p.from_address(id(deque)+11*ptr_size)
b = c_void_p.from_address(id(deque)+29*ptr_size).value
if sys.version_info.major == 2:
c = c_void_p.from_address(b + 29*ptr_size)
else:
c = c_void_p.from_address(b + 41*ptr_size)
a.value = c.value
mystery1 = {'a': deque(['a', 'a'])}
mystery2 = {'a': deque(['a', 'b'])}
assert type(mystery1) is dict
assert type(mystery2) is dict
assert str(mystery1) != str(mystery2)
assert str(mystery1) == str(mystery2)
print("All checks passed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment