5E PROGRAMSExcellence (6 points): Complete any three programs within 50 hours.
Advanced (5 points): Complete any three programs by the end of the cycle. Proficient (4 points): Complete any two programs by the end of Cycle 5. Basic (3 points): Complete one program by the end of cycle 5. Below Basic (2 points): Unsuccessfully attempt one program. |
|
BoatyMcBoatFace
Boaty McBoatFace needs a new face. Currently, he has five colors: red, orange, green, white, and yellow. Write a program that asks Boaty to toot his horn once for every color in the world he likes and sounding something else to indicate he is done. Then, output how many different ways Boaty could be re-colored in the five areas.
INPUT:
TOOT TOOT TOOT TOOT TOOT TOOT TOOT TOOT AROOGA
OUTPUT:
6720
INPUT:
TOOT TOOT TOOT TOOT TOOT BEEP
OUTPUT:
120
INPUT:
TOOT TOOT TOOT DING
OUTPUT:
0
Boaty McBoatFace needs a new face. Currently, he has five colors: red, orange, green, white, and yellow. Write a program that asks Boaty to toot his horn once for every color in the world he likes and sounding something else to indicate he is done. Then, output how many different ways Boaty could be re-colored in the five areas.
INPUT:
TOOT TOOT TOOT TOOT TOOT TOOT TOOT TOOT AROOGA
OUTPUT:
6720
INPUT:
TOOT TOOT TOOT TOOT TOOT BEEP
OUTPUT:
120
INPUT:
TOOT TOOT TOOT DING
OUTPUT:
0
FancyCalc
Example
This program emulates a calculator in that it presents the user with a menu of choices then performs mathematical functions. Give the user three options with a single character input: Permutations and Combinations, Probability to Odds, and Odds to Probability.
If the user chooses Permutations and Combinations, ask for inputs r (the number of items to select) and n (the number of items in the set). Output the number of permutations and combinations possible.
TEST DATA:
INPUTS = r = 7, n = 10
OUTPUTS: Permutations = 604800, Combinations = 120
If the user chooses either of the Probability/Odds functions, take one as an input and output the other.
Note: The inputs can come in as two numbers in separate readlns. So, the odds 3:7 would be read in as "3, enter, 7, enter". Do not include the colon or slash in between the numbers.
TEST DATA:
INPUT = 4/5
OUTPUT: 4:1
INPUT = 2:9
OUTPUT = 2/11
Example
This program emulates a calculator in that it presents the user with a menu of choices then performs mathematical functions. Give the user three options with a single character input: Permutations and Combinations, Probability to Odds, and Odds to Probability.
If the user chooses Permutations and Combinations, ask for inputs r (the number of items to select) and n (the number of items in the set). Output the number of permutations and combinations possible.
TEST DATA:
INPUTS = r = 7, n = 10
OUTPUTS: Permutations = 604800, Combinations = 120
If the user chooses either of the Probability/Odds functions, take one as an input and output the other.
Note: The inputs can come in as two numbers in separate readlns. So, the odds 3:7 would be read in as "3, enter, 7, enter". Do not include the colon or slash in between the numbers.
TEST DATA:
INPUT = 4/5
OUTPUT: 4:1
INPUT = 2:9
OUTPUT = 2/11
WrapItUp
A local deli's wraps are a hit, and as part of the marketing team you have been asked to calculate the number of possible ways that an order could be placed.
There are a five key component to a wrap: the wrap type, the dressing, the main item, the cheese, and the toppings.
There will always be one type of wrap (like spinach herb or tomato basil), but potentially a customer could order every dressing (honey mustard, balsamic), every main item (turkey, chicken salad, tofu), every cheese (muenster, gouda), and every topping (lettuce, sweet peppers, onions)--or they could order none of any of these things and just get the wrap (i.e. the infant/picky toddler menu).
The inputs of this program are the numbers of types of each component that are available, and the output is the number of wraps that could potentially be made.
TEST DATA:
INPUTS
Wrap Type: 3
Dressings: 4
Main Items: 5
Cheeses: 4
Toppings: 12
OUTPUT
100663296
INPUTS
Wrap Type: 7
Dressings: 6
Main Items: 8
Cheeses: 6
Toppings: 11
OUTPUT
15032385536
A local deli's wraps are a hit, and as part of the marketing team you have been asked to calculate the number of possible ways that an order could be placed.
There are a five key component to a wrap: the wrap type, the dressing, the main item, the cheese, and the toppings.
There will always be one type of wrap (like spinach herb or tomato basil), but potentially a customer could order every dressing (honey mustard, balsamic), every main item (turkey, chicken salad, tofu), every cheese (muenster, gouda), and every topping (lettuce, sweet peppers, onions)--or they could order none of any of these things and just get the wrap (i.e. the infant/picky toddler menu).
The inputs of this program are the numbers of types of each component that are available, and the output is the number of wraps that could potentially be made.
TEST DATA:
INPUTS
Wrap Type: 3
Dressings: 4
Main Items: 5
Cheeses: 4
Toppings: 12
OUTPUT
100663296
INPUTS
Wrap Type: 7
Dressings: 6
Main Items: 8
Cheeses: 6
Toppings: 11
OUTPUT
15032385536
CommitteeCommitted
A high school has decided that their student council is not effective at determining what its students really want, so it decides to transfer its governmental style from a representative democracy (in which elected officials' votes in a "congress" represent their citizens) to a "democracy by committee".
The new by-laws for such committees have been written as follows:
"Each homeroom of the school shall be given a vote on all voteable decisions. Within each homeroom, a committee shall be formed (by majority election) of a size equal to the next odd integer greater than or equal to 20% (one-fifth) of the number of students in that homeroom. Each committee shall contain a balanced number of males and females, but since the size of the committee is odd the majority shall go to the gender that is the majority of the homeroom. If there are equal numbers of males and females in the homeroom, then a coin flip by the teacher (which must be a public event) shall decide the last member's gender by the rule "heads = female, tails = male". Any student may opt out of being on the committee prior to the vote for committee formation."
Write a program that takes the following as inputs:
Output the following:
TEST DATA:
INPUTS: 21 students in HR, 8 males, 3 females opting out, 2 males opting out
OUTPUTS:
This homeroom has 8 males and 13 females.
This homeroom has 6 males and 10 females willing to serve on the committee.
The committee will be of size 5.
No coin flip
There will be 2 males and 3 females on this committee.
There are 1800 possible committee combinations in this homeroom.
INPUTS: 15 students in HR, 8 males, 0 females opting out, 1 male opting out
OUTPUTS:
This homeroom has 8 males and 7 females.
This homeroom has 7 males and 7 females willing to serve on the committee.
The committee will be of size 3.
No coin flip
There will be 2 males and 1 female on this committee.
There are 147 possible committee combinations in this homeroom.
INPUTS: 26 students in HR, 13 males, 5 females opting out, 10 males opting out
OUTPUTS:
This homeroom has 13 males and 13 females.
This homeroom has 3 males and 8 females willing to serve on the committee.
The committee will be of size 7.
Coin flip is random
If heads:
A high school has decided that their student council is not effective at determining what its students really want, so it decides to transfer its governmental style from a representative democracy (in which elected officials' votes in a "congress" represent their citizens) to a "democracy by committee".
- When a voteable decision must be made that impacts all students, a discussion on the topic will be held within a homeroom.
- A committee of students in that homeroom will then attend a summit in which all committees will debate the issue.
- Finally, each committee will vote to give represent their homeroom in that decision.
The new by-laws for such committees have been written as follows:
"Each homeroom of the school shall be given a vote on all voteable decisions. Within each homeroom, a committee shall be formed (by majority election) of a size equal to the next odd integer greater than or equal to 20% (one-fifth) of the number of students in that homeroom. Each committee shall contain a balanced number of males and females, but since the size of the committee is odd the majority shall go to the gender that is the majority of the homeroom. If there are equal numbers of males and females in the homeroom, then a coin flip by the teacher (which must be a public event) shall decide the last member's gender by the rule "heads = female, tails = male". Any student may opt out of being on the committee prior to the vote for committee formation."
Write a program that takes the following as inputs:
- The number of students in the homeroom.
- The number of males in the homeroom.
- Please assume that all students identify with one gender in this situation.
- The number of females opting out of the committee
- The number of males opting out of the committee
Output the following:
- The number of males and females in the homeroom.
- The number of males and females who are willing to serve on the committee.
- The size of the committee.
- The coin flip event, if necessary.
- The number of males and females on the committee.
- The number of possible committee combinations in this homeroom.
TEST DATA:
INPUTS: 21 students in HR, 8 males, 3 females opting out, 2 males opting out
OUTPUTS:
This homeroom has 8 males and 13 females.
This homeroom has 6 males and 10 females willing to serve on the committee.
The committee will be of size 5.
No coin flip
There will be 2 males and 3 females on this committee.
There are 1800 possible committee combinations in this homeroom.
INPUTS: 15 students in HR, 8 males, 0 females opting out, 1 male opting out
OUTPUTS:
This homeroom has 8 males and 7 females.
This homeroom has 7 males and 7 females willing to serve on the committee.
The committee will be of size 3.
No coin flip
There will be 2 males and 1 female on this committee.
There are 147 possible committee combinations in this homeroom.
INPUTS: 26 students in HR, 13 males, 5 females opting out, 10 males opting out
OUTPUTS:
This homeroom has 13 males and 13 females.
This homeroom has 3 males and 8 females willing to serve on the committee.
The committee will be of size 7.
Coin flip is random
If heads:
- There will be 3 males and 4 females on this committee.
- There are 70 possible committee combinations in this homeroom.
- There will be 4 males and 3 females on this committee.
- There are 0 possible combinations in this homeroom.
ABC: PutMeInCoach
Mr. Stacey Kengel, a few years retired from his last coaching stint in the big leagues, has been put in charge of a tee-ball team of 16 five-and six-year olds. Some days, 'ol Stacey wants to strategize and outwit the other manager like it's his glory days. Other days, it's a bunch of five- and six-year olds so...who cares, let 'em have fun.
Here's some starting information:
Write a program that asks Stacey for the following values:
The program should output how many possible ways there are to field the positions, according to the following conditions:
TEST DATA
INPUTS
12 kids appeared
2 want to pitch
2 want to catch
1 wants to play first base
4 want to play infield
3 want play outfield
Stacey wants 3 infielders and 3 outfielders
OUTPUTS:
There are 576 ways to field this team.
--------------
INPUTS
16 kids appeared
3 want to pitch
2 want to catch
2 want to play first base
6 want to play infield
3 want play outfield
Stacey wants 4 infielders and 2 outfielders
OUTPUTS:
There are 25920 ways to field this team.
--------------
INPUTS
10 kids appeared
0 want to pitch
1 wants to catch
1 want to play first base
2 want to play infield
6 want play outfield
Stacey wants 2 infielders and 4 outfielders
OUTPUTS:
There are 3628800 ways to field this team.
Mr. Stacey Kengel, a few years retired from his last coaching stint in the big leagues, has been put in charge of a tee-ball team of 16 five-and six-year olds. Some days, 'ol Stacey wants to strategize and outwit the other manager like it's his glory days. Other days, it's a bunch of five- and six-year olds so...who cares, let 'em have fun.
Here's some starting information:
- Even though 16 kids are on the team, there's no guarantee that all 16 will show up for a game. Nine players take the field at a time.
- He likes to ask every kid which position he/she wants to play prior to each game. The kid's choices are pitcher, catcher, first base, infield, or outfield. Stacey knows there is no need to be specific about other positions (shortstop, left field, etc.) at this age, but Stacey will place them according to his wishes. Therefore, if a kid says they want infield, Stacey will place him/her at a position of his choosing.
- Depending on various factors, Stacey will take the six combined infielders and outfielders and stack them 1-5, 2-4, 3-3, 4-2, or 5-1 (infielders to outfielders).
Write a program that asks Stacey for the following values:
- How many kids showed up that day for the game.
- If less than nine kids showed up, the program should output "FORFEIT" and quit afterwards.
- How many wanted to play each of the five positions.
- If Stacey's inputs do not add up to the number of kids who showed up, make him restart the entire program.
- How many infielders and outfielders to assign that day.
- If Stacey's inputs do not add up to 6, make him restart the entire program.
The program should output how many possible ways there are to field the positions, according to the following conditions:
- Stacey will either make every kid happy OR not concern himself with making any kid happy regarding field positions. Therefore...
- If no one wanted any of the positions, or there were less than six combined infielders/outfielders, or there were less than the necessary number of infielders and outfielders Stacey wanted, then ANY kid could play any position.
- If that was not the case, then the number of lineups stay within the boundaries set: 1 pitcher/catcher/first base out of all the kids who wanted to pitch/catch/play first base, x infielders and y outfielders out of the number who wanted to play those (Stacey picks x and y). Note: The Fundamental Counting Principle is central to your calculation. Also, 0! = 1.
TEST DATA
INPUTS
12 kids appeared
2 want to pitch
2 want to catch
1 wants to play first base
4 want to play infield
3 want play outfield
Stacey wants 3 infielders and 3 outfielders
OUTPUTS:
There are 576 ways to field this team.
--------------
INPUTS
16 kids appeared
3 want to pitch
2 want to catch
2 want to play first base
6 want to play infield
3 want play outfield
Stacey wants 4 infielders and 2 outfielders
OUTPUTS:
There are 25920 ways to field this team.
--------------
INPUTS
10 kids appeared
0 want to pitch
1 wants to catch
1 want to play first base
2 want to play infield
6 want play outfield
Stacey wants 2 infielders and 4 outfielders
OUTPUTS:
There are 3628800 ways to field this team.
ABC: PlayinPonies
Despite being a bad habit both financially and mentally (and explicitly NOT recommended by Mr. Kindt), horse racing makes for some very interesting mathematical applications.
One type of wager in a horse race is called a trifecta. In this, the participant must select three horses in a particular order.
Any of those wagers can be made in three forms (straight, key, and box). Suppose that in a certain horse race the order of finish for the three fastest horses was Dishonest Wolf (DW) , Portland Phew (PP), and Egyptian President (EP)**. Then, :
Alternatively, suppose ten horses named the letters A through J were in the race and you wished to make a trifecta bet on B to win, F to place (come in 2nd), and H to show (come in 3rd).
A trifecta straight would win ONLY in the order B/F/H.
A trifecta key would win for B/F/H or B/H/F.
A trifecta box would win for B/F/H, B/H/F, F/B/H, F/H/B, H/B/F, and H/F/B.
Your odds are not good, even with the box. There are 720 ways for three horses to finish in a ten-horse race…giving you a 1/120 or 0.83% chance of winning (assuming the horses are all equal in ability).
However, all horses are not equal in ability and thus are given odds of winning, such as 5:2 or 100:1. In horse racing, the odds ratio is unsuccessful: successful. Therefore, 99:1 means the odds of winning are 1/100.
Picking multiple horses to win requires you to multiply probabilities and possibly permutations. An exacta straight where your chosen win has 3:1 odds and your chosen place has 9:1 odds would have a probability of 1/4 * 1/10 = 1/40 = 0.0254 or 2.5%. If you box this exacta, you would be able to multiply that % by 2…thus giving you a 5% chance of victory (odds 19:1).
However, lower odds will allow you to win more money. Suppose in the above situation with the exacta straight, where the probability of winning was 2.5%, a $10 wager was used. The payout would be 10/0.025 = $400. For the exacta box at $10, the payout would be 10/0.05 = $200.
Your program will ask for the following inputs for a trifecta: the number of horses in the race, the odds of the horses in the order you believe they will finish, and the wager amount.
The output should be the expected payoff of the straight, key, and box and a recommendation on which to play. Expected payoff is the likelihood of the random occurrence of the success times the amount you would win if you were successful.
TEST DATA:
INPUTS:
10 horses in the race
Horse 1 Odds = 3:1
Horse 2 Odds = 5:2
Horse 3 Odds = 19:1
Wager = 50
BEHIND THE SCENES VALUES:
Random Probability Straight = 1/P(10, 3) = 1/720
Random Probability Key = 1/10 * 1/P(9. 2) = 1/720
Random Probability Box = 1/C(10, 3) = 1/120
Straight Combined Probability Based on Odds = 1/4 * 2/7 * 1/20 = 0.00357
Key Combined Probability Based on Odds = 0.00357 * 2 = 0.00714 (There are two ways: Guessing ABC would win ABC or ACB)
Box Combined Probability Based on Odds = = 0.00357 * 6 = 0.0214 (There are six ways: Guessing ABC would win ABC, ACB, BAC, BCA, CBA, or CAB).
Straight Payout = 50/0.00357 = 14005.60
Key Payout = 50/0.00714 = 7002.80
Box Payout = 50/0.0214 = 2336.45
OUTPUTS:
Expected Payoff Straight: $19.45
Expected Payoff Key: $9.73
Expected Payoff Box: $19.47
Play the Box in this race.
Despite being a bad habit both financially and mentally (and explicitly NOT recommended by Mr. Kindt), horse racing makes for some very interesting mathematical applications.
One type of wager in a horse race is called a trifecta. In this, the participant must select three horses in a particular order.
Any of those wagers can be made in three forms (straight, key, and box). Suppose that in a certain horse race the order of finish for the three fastest horses was Dishonest Wolf (DW) , Portland Phew (PP), and Egyptian President (EP)**. Then, :
- Straight = The horses must be selected in the exact order of finish. In this race, the only straight trifecta would have been DW, PP, EP.
- Key = The winning horse must be selected correctly, then the other two horses can be in any order. If you pick the horses in 1st-2nd-3rd or 1st-3rd-2nd, you win. In this instance, DW, PP, EP or DW, EP, PP would have won on a key trifecta.
- Box = The order of the horses does not matter in any way as long as they are all in the top three. So, DW, PP, EP would have been as much of a winner as any other order of those three, like EP, DW, PP.
Alternatively, suppose ten horses named the letters A through J were in the race and you wished to make a trifecta bet on B to win, F to place (come in 2nd), and H to show (come in 3rd).
A trifecta straight would win ONLY in the order B/F/H.
A trifecta key would win for B/F/H or B/H/F.
A trifecta box would win for B/F/H, B/H/F, F/B/H, F/H/B, H/B/F, and H/F/B.
Your odds are not good, even with the box. There are 720 ways for three horses to finish in a ten-horse race…giving you a 1/120 or 0.83% chance of winning (assuming the horses are all equal in ability).
However, all horses are not equal in ability and thus are given odds of winning, such as 5:2 or 100:1. In horse racing, the odds ratio is unsuccessful: successful. Therefore, 99:1 means the odds of winning are 1/100.
Picking multiple horses to win requires you to multiply probabilities and possibly permutations. An exacta straight where your chosen win has 3:1 odds and your chosen place has 9:1 odds would have a probability of 1/4 * 1/10 = 1/40 = 0.0254 or 2.5%. If you box this exacta, you would be able to multiply that % by 2…thus giving you a 5% chance of victory (odds 19:1).
However, lower odds will allow you to win more money. Suppose in the above situation with the exacta straight, where the probability of winning was 2.5%, a $10 wager was used. The payout would be 10/0.025 = $400. For the exacta box at $10, the payout would be 10/0.05 = $200.
Your program will ask for the following inputs for a trifecta: the number of horses in the race, the odds of the horses in the order you believe they will finish, and the wager amount.
The output should be the expected payoff of the straight, key, and box and a recommendation on which to play. Expected payoff is the likelihood of the random occurrence of the success times the amount you would win if you were successful.
TEST DATA:
INPUTS:
10 horses in the race
Horse 1 Odds = 3:1
Horse 2 Odds = 5:2
Horse 3 Odds = 19:1
Wager = 50
BEHIND THE SCENES VALUES:
Random Probability Straight = 1/P(10, 3) = 1/720
Random Probability Key = 1/10 * 1/P(9. 2) = 1/720
Random Probability Box = 1/C(10, 3) = 1/120
Straight Combined Probability Based on Odds = 1/4 * 2/7 * 1/20 = 0.00357
Key Combined Probability Based on Odds = 0.00357 * 2 = 0.00714 (There are two ways: Guessing ABC would win ABC or ACB)
Box Combined Probability Based on Odds = = 0.00357 * 6 = 0.0214 (There are six ways: Guessing ABC would win ABC, ACB, BAC, BCA, CBA, or CAB).
Straight Payout = 50/0.00357 = 14005.60
Key Payout = 50/0.00714 = 7002.80
Box Payout = 50/0.0214 = 2336.45
OUTPUTS:
Expected Payoff Straight: $19.45
Expected Payoff Key: $9.73
Expected Payoff Box: $19.47
Play the Box in this race.