Last active
December 15, 2015 23:19
-
-
Save toumorokoshi/5339362 to your computer and use it in GitHub Desktop.
An example of how I would answer the fibonacci question,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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