Skip to content

Instantly share code, notes, and snippets.

@toumorokoshi
Last active December 15, 2015 23:19
Show Gist options
  • Save toumorokoshi/5339362 to your computer and use it in GitHub Desktop.
Save toumorokoshi/5339362 to your computer and use it in GitHub Desktop.
An example of how I would answer the fibonacci question,
def fib(n):
assert n > 0, "ERROR: n is less than 0!"
if n == 0:
return 1
curr, prev, results = 1, 0, ['1']
while n > 0:
curr, prev = curr + prev, curr
results.append(str(curr))
n -= 1
return ",".join(results)
def test_fib():
try:
fib(-1)
print "ERROR! No error negative input"
except AssertionError:
pass
assert(fib(1) == "1,1")
assert(fib(2) == "1,1,2")
assert(fib(3) == "1,1,2,3")
test_fib()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment