Functions and Recursion Problems
Functions and Recursion Problems
3. Using the turtle graphics module, write a recursive program to display a Koch snowflake
4. Write a function that takes a string as a parameter and returns True if the string is a
palindrome, False otherwise. Remember that a string is a palindrome if it is spelled the
same both forward and backward. for example: radar is a palindrome. Palindromes can
also be phrases, but you need to remove the spaces and punctuation before checking.
5. Write a program to solve the following problem: You have two jugs: a 4-gallon jug and
a 3-gallon jug. Neither of the jugs have markings on them. There is a pump that can be
used to fill the jugs with water. How can you get exactly two gallons of water in the 4-
gallon jug? Generalize the problem above so that the parameters to your solution include
the sizes of each jug and the final amount of water to be left in the larger jug.
6. Write a program that solves the following problem: Three missionaries and three
cannibals come to a river and find a boat that holds two people. Everyone must get across
the river to continue on the journey. However, if the cannibals ever outnumber the
missionaries on either bank, the missionaries will be eaten. Find a series of crossings that
will get everyone safely to the other side of the river
7. Write a function that gets as parameters two strings. The function returns the number of
characters that the strings have in common. Each character counts only once, e.g., the
strings "bee" and "peer" only have one character in common (the letter “e”). You can
consider capitals different from lower case letters. Note: the function should return the
number of characters that the strings have in common, and not print it. To test the
function, you can print the result in your main program.
8. The Grerory-Leibnitz series approximates pi as 4 ∗ (1/1 − 1/3 + 1/5 − 1/7 + 1/9...). Write
a function that returns the approximation of pi according to this series. The function gets
one parameter, namely an integer that indicates how many of the terms between the
parentheses must be calculated.