Question
Solve the following programming problems in Python: Write a function filter that takes a predicate and a list as argument and returns a list of
Solve the following programming problems in Python:
- 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 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 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
Submit a zip file that contains your source files and a Word document that contains screen captures showing your programs successful executionincluding several test cases to show your solutions work as expected.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started