North Korea bans cell phones, so up to a few years ago it was overrun with Pokemon. Nobody to catch one, let alone them all.
The solution was to release Carnimon, creatures that feed on Pokemon. There are three species: Burner, Biter, and Borer. It worked. Pokemon are not clogging the streets, interrupting theoretical food deliveries.
Of course, now the Carnimon are out of control. (Sigh)
Dear Leader has ordered that peasants..., er, patriotic heroes and righteous toilers (PHARTs) (which is everyone but him and his special people, who keep the PHARTs from escaping) catch Carnimon per week, using Caricubes, like Pokeballs but made in North Korea, rather than made by immoral foreigners who don't control their PHARTs.
PHARTs who don't meet their quota will be punished. They'll be forced to read a regular programming textbook. So, you know, motivation.
Carnicubes are all the same size, one cubic gan. That's the standard unit of length, named for the reported length of Dear Leader's great grandmother's liver. A Carnicube can hold one Burner, three Biters, or four Borers. You can't mix species in a Carnicube or they'll carn each other. DL doesn't want that, since he plans Carnimon to be the main source of protein in PHART diets. And they'd better not complain! DL wants them silent.
Being a tough but fair leader, DL won't make every PHART catch Carimon. He'll exempt those who are too young, or who are about to contribute their bodies to enriching NK's fields, in a program called Mulch Mom for Might. He'll exempt his PHART-squeezing pals, too, of course. He needs them to keep the plebs having the right PHARTy thoughts.
Write a program to estimate how many Carnicubes DL will need each week, based on:
- The number of PHARTs who'll participate.
- The number of each type of Carnimon each PHART will catch.
- Expected percentage of Carnicube loss, through poor PHARTmanship, falling off the back of a buffalo cart, or whatever.
- Whether Dear Leader is happy today.
Here's some I/O. Oh, were it says "volunteer?" In DearLeaderLand, volunteering is not voluntary.
The simplest case:
- Carnicube Count
- ======== =====
- Hail Dear Leader, from whom all good flows!
- How many PHARTs will volunteer for this glorious work? 1
- Tell me about the weekly quotas for each PHART.
- Burners? 1
- Biters? 1
- Borers? 1
- Tell me about Carnicube loss.
- Expected Carnicube loss (%)? 100
- Tell me about Dear Leader
- Is Dear Leader happy today (y/n)? y
- ==== Results ====
- Dear Leader is happy! All rejoice!
- PHARTs: 1
- Cubes needed for each PHART
- ----- ------ --- ---- -----
- To capture burners: 1 per PHART
- To capture biters: 1 per PHART
- To capture borers: 1 per PHART
- Total cubes needed before accounting for loss: 3 cubes
- Cube loss allowance: 3 cubes
- Total cubes needed: 6
- Hail Dear Leader, from whom all good flows!
Notice the line To capture biters: 1 per PHART
. The quota is one biter, and you can put three biters into a cube, so that's 0.33 cubes, right? No, you need to go up to the next highest number. So they need one cube each, even though most of it will be MT.
The easiest way to do that is to use the ceil()
function. For example:
- import math
- yummy_pi = 3.14159
- round_me_up_some_pi = math.ceil(yummy_pi)
- print(round_me_up_some_pi)
This prints 4.
ceil()
isn't a built-in function. It's in the math
library. (Yay! Math!) You import the library (line 1) and tell your program to use ceil()
in that library (line 3).
Give ceil()
a number, and it will return the next largest whole number. Or just the number, if it's already whole.
Here's some stuff from my solution:
- biter_cubes_per_phart = math.ceil(biters_per_phart / 3)
- ...
- lost_cubes = cubes_before_loss * (loss_percent/100)
- lost_cubes = math.ceil(lost_cubes)
You can fit three biters in a cube. The first line works out the number of cubes you'll need for the number of biters you have, then rounds up.
The last two lines do the same thing for the lost cube allowance.
Another example:
- Carnicube Count
- ======== =====
- Hail Dear Leader, from whom all good flows!
- How many PHARTs will volunteer for this glorious work? 100
- Tell me about the weekly quotas for each PHART.
- Burners? 2
- Biters? 7
- Borers? 9
- Tell me about Carnicube loss.
- Expected Carnicube loss (%)? 10
- Tell me about Dear Leader
- Is Dear Leader happy today (y/n)? y
- ==== Results ====
- Dear Leader is happy! All rejoice!
- PHARTs: 100
- Cubes needed for each PHART
- ----- ------ --- ---- -----
- To capture burners: 2 per PHART
- To capture biters: 3 per PHART
- To capture borers: 3 per PHART
- Total cubes needed before accounting for loss: 800 cubes
- Cube loss allowance: 80 cubes
- Total cubes needed: 880
- Hail Dear Leader, from whom all good flows!
The number of cubes per PHART are rounded up as expected.
Here's a more realistic run:
- Carnicube Count
- ========= =====
- Hail Dear Leader, from whom all good flows!
- How many PHARTs will volunteer for this glorious work? 15000000
- Tell me about the weekly quotas for each PHART.
- Burners? 2
- Biters? 5
- Borers? 12
- Tell me about Carnicube loss.
- Expected Carnicube loss (%)? 10
- Tell me about Dear Leader
- Is Dear Leader happy today (y/n)? n
- ==== Results ====
- Dear Leader is unhappy. His PHARTs are failing him.
- PHARTs: 15000000
- Cubes needed for each PHART
- ----- ------ --- ---- -----
- To capture burners: 4 per PHART
- To capture biters: 4 per PHART
- To capture borers: 6 per PHART
- Total cubes needed before accounting for loss: 210000000 cubes
- Cube loss allowance: 21000000 cubes
- Total cubes needed: 231000000
- Hail Dear Leader, from whom all good flows!
All those 0s in the large numbers makes it easy for readers to make mistakes. What I'd do for realsies is add , separators, like humans normally do. You can google that if you want.
Submit your solution through this site, not Moodle. The usual rules apply.