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
import math | |
def stddev(numbers): | |
n = len(numbers) | |
mean = sum(numbers) / n | |
dev = [x - mean for x in numbers] | |
dev2 = [x * x for x in dev] | |
return math.sqrt(sum(dev2) / n) |
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
/* ----------------------------------------------------------------------- | |
1. Show the cycle for 3. | |
What is the cycle length? | |
[Collatz] | |
(2 pts) | |
3, 10, 5, 16, 8, 4, 2, 1 | |
8 | |
*/ |
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 range(begin, end = None, step = 1): | |
if step == 0: | |
raise Exception("Step size cannot be 0") | |
if end == None: | |
end, begin = begin, 0 | |
while (abs(begin + step - end)) <= (abs(begin - end)): | |
yield begin | |
begin += step | |
assert(list(range(10)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) |
NewerOlder