Question: 1. Write a function filter that takes a predicate and a list as argument and returns a list of only those elements that satisfy the
1. Write a function filter that takes a predicate and a list as argument and returns a list of only those elements that satisfy the predicate. Example: (filter odd? '(1 2 3 4 5 6 7 8 9)) ==> (1 3 5 7 9)
2. Write a function explode that takes a symbol as input and returns a list of symbols corresponding to its individual characters. Examples: (explode 'apple) ==> (a p p l e) (explode 'a) ==> (a)
3. Write a function implode that is the inverse of explode. It takes a list of one character symbols and combines them to form a single symbol. Examples: (implode '(a p p l e)) ==> apple (implode (explode 'NCU)) ==> NCU
4. Write a program to solve the following problem:
Lieutenant Uhura is visiting the space station K7 from the USS Enterprise. While there, she meets a man named Cyrano Jones who sells her a pet: a ball of fur called a Tribble. Doctor McCoy later examines the Tribble and makes the following observations: Tribbles are born pregnant and reproduce asexually. Tribbles never die except by poisoning. After twelve hours of lifeand every twelve hours thereaftera Tribble will give birth to a litter of ten baby Tribbles. Assuming the Tribble that Lieutenant Uhura purchased was a newborn and it was the only one brought back from the space station, after three Earth days, how many Tribbles will there be on the Enterprise? After four days? Your program should be able to predict the number of Tribbles after any length of time (in hours). Examples: (tribbles 0) ==> 0 # the original Tribble (tribbles 12) ==> 11 # the original Tribble and its 10 offspring (tribbles 24) ==> 121 (tribbles 36) ==> 1331 (tribbles 48) ==> 14641 (tribbles 60) ==> 161051
5. Write a program to solve the following puzzle:
Dr. Z, the ruler of the ancient kingdom of Joejb, has her political foes locked up in individual cells in her dungeon. There is a total of 100 cells. On their Independence Day as all the Joejbians were celebrating, Dr. Z decided to release some of her political prisoners. But being the maverick she is, she does the following: She goes to the first cell and opens it, she goes to 2nd and opens, and she continues to open the 3rd, 4th ... all the way to the 100th cell. She then comes back to the 2nd cell and closes it. She closes the 4th and in steps of 2, she closes the 6th, 8th ... 98th and 100th cells. She then comes to the 3rd cell and this time in steps of 3 she visits each cell (3rd, 6th, 9th ...) and if the cell is open she closes it and if its closed, she opens it. She repeats this process of opening closed cells and closing open cells in steps of 4, 5 ... all the way up to a step of 100. In the end, she decrees that all the prisoners in the cells that remain open are free to go. Who are those lucky prisoners (i.e., what are their cell numbers)?
Some problems in this section were partially adapted from http://www.cs.indiana.edu/classes/b551-leak/scheme_practice.html
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
