Note: I am not an official teacher or GSI for any of the courses listed on this site unless otherwise stated. Any problems and notes are created from my own observations and may not accurately reflect the course's content.

Higher Order Functions #3

A peak is a number that is preceded and follwed by a smaller number. The mountain_climber function is a curried function that takes non-negative single digit integers and prints them if they are a peak. The first and last input should not be printed. Refer to the doctests for examples how to use the mountain_climber function.

def mountain_climber(rock, crevice=10):
	""" Curried function that takes non-negative single digits and prints
		   inputs that are preceded and followed by larger digits.

		   >>> f = mountain_climber(3)(4)(5)(7)(2)(3)(1)(4)
		   7
		   3
		   >>> g = mountain_climber(1)(1)(1)(2)
		   >>> h = mountain_climber(1)(4)(1)(3)(1)(2)(1)(1)
		   4
		   3
		   2
		   >>> k = mountain_climber(6)
		   """
	def climber(rope, ridge):
		if _________________________________ :
			print ( _________________________________ )
		return _________________________________

	return lambda x: climber( ________________ , ________________ )

Solution

Have a question? Found an error? Email me at imran.khaliq@berkeley.edu with the URL of the page and a short description.