Skip to content

Instantly share code, notes, and snippets.

@fuzzy-focus
Created April 28, 2016 12:03
Show Gist options
  • Save fuzzy-focus/f076a5d8bb343cac4a181d35f8c1cc21 to your computer and use it in GitHub Desktop.
Save fuzzy-focus/f076a5d8bb343cac4a181d35f8c1cc21 to your computer and use it in GitHub Desktop.
## First ##########################################
mystery = iter('')
# challenge code
def print_stuff(stuff):
if stuff:
print "Printing some stuff"
for x in stuff:
print x
else:
print "Nothing to print"
print_stuff(mystery)
## Second ##########################################
mystery1 = 1e16
mystery2 = 2e16
# challenge code
def sum_numbers(low, high):
total = 0
while low <= high:
total += low
low += 1
return total
# Make sure we are using valid numeric values
assert float('-inf') < mystery1 < float('inf')
assert float('-inf') < mystery2 < float('inf')
print sum_numbers(mystery1, mystery2)
# result:
# Program never terminates
## Third ##########################################
mystery1 = dict()
mystery2 = {0:mystery1}
mystery1[0]=mystery2
# These are exactly dicts, not subclasses of dict
assert type(mystery1) is dict
assert type(mystery2) is dict
print mystery1 == mystery2
# result:
# RuntimeError: maximum recursion depth exceeded in cmp
# challenge code
## Forth ##########################################
import random
class Forth(object):
def __repr__(self): return str(random.random())
mystery1=mystery2={0: Forth()}
# challenge code
assert type(mystery1) is dict
assert type(mystery2) is dict
assert str(mystery1) != str(mystery2)
assert mystery1 == mystery2
print "All checks passed"
# output:
# All checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment