Home CS61A: Lecture 7
Post
Cancel

CS61A: Lecture 7

Lecture

Function Examples

1
2
3
4
5
6
7
8
9
10
11

 def nearest_prime(n):
	k = 0
	while True:
		if (is_prime(n+k)):
			return n+k
		if is_prime(n-k):
			k = -k
		else:
			k+=1
1
2
3
4
curry = lambda f: lambda x: lambda y: f(x,y)
reverse = lambda g: lambda x, y: g(y,x)
square = curry(reverse(pow))(2)(10)
square
1
100
This post is licensed under CC BY 4.0 by the author.

CS61A: Decorators

CS61A: Recursion