Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lovely Lucky Lambs #15

Open
the-vampiire opened this issue Oct 5, 2018 · 2 comments
Open

Lovely Lucky Lambs #15

the-vampiire opened this issue Oct 5, 2018 · 2 comments
Labels
Hacktoberfest wizard apprentice if you solve these you are on your way to being a wizard

Comments

@the-vampiire
Copy link
Owner

the-vampiire commented Oct 5, 2018

from Google Foobar

Challenge

  • Write a function called answer(total_lambs), where total_lambs is the integer number of LAMBs in the handout you are trying to divide.
  • It should return an integer which represents the difference between the minimum and maximum number of henchmen who can share the LAMBs (that is, being as generous as possible to those you pay and as stingy as possible, respectively) while still obeying all of the above rules to avoid a revolt.

Problem Statement:
Lovely Lucky LAMBs

Being a henchman isn't all drudgery. Occasionally, when Commander Lambda is feeling generous, she'll hand out Lucky LAMBs (Lambda's All-purpose Money Bucks). Henchmen can use Lucky LAMBs to buy things like a second pair of socks, a pillow for their bunks, or even a third daily meal!
However, actually passing out LAMBs isn't easy. Each henchman squad has a strict seniority ranking which must be respected - or else the henchmen will revolt and you'll all get demoted back to minions again!
There are 4 key rules which you must follow in order to avoid a revolt:
1. The most junior henchman (with the least seniority) gets exactly 1 LAMB. (There will always be at least 1 henchman on a team.)
2. A henchman will revolt if the person who ranks immediately above them gets more than double the number of LAMBs they do.
3. A henchman will revolt if the amount of LAMBs given to their next two subordinates combined is more than the number of LAMBs they get. (Note that the two most junior henchmen won't have two subordinates, so this rule doesn't apply to them. The 2nd most junior henchman would require at least as many LAMBs as the most junior henchman.)
4. You can always find more henchmen to pay - the Commander has plenty of employees. If there are enough LAMBs left over such that another henchman could be added as the most senior while obeying the other rules, you must always add and pay that henchman.

notes

Note that you may not be able to hand out all the LAMBs. A single LAMB cannot be subdivided. That is, all henchmen must get a positive integer number of LAMBs.
For instance, if you had 10 LAMBs and were as generous as possible, you could only pay 3 henchmen (1, 2, and 4 LAMBs, in order of ascending seniority), whereas if you were as stingy as possible, you could pay 4 henchmen (1, 1, 2, and 3 LAMBs). Therefore, answer(10) should return 4-3 = 1.

sample inputs / outputs

Inputs:
(int) total_lambs = 10
Output:
(int) 1
Inputs:
(int) total_lambs = 143
Output:
(int) 3

@the-vampiire the-vampiire added wizard apprentice if you solve these you are on your way to being a wizard Hacktoberfest google foobar and removed google foobar labels Oct 5, 2018
@Kushagra-0801
Copy link
Contributor

Is there anything like a lower or higher limit on the number of LAMBs?
And is there always only a single henchman at a given seniority level?

@the-vampiire
Copy link
Owner Author

no limit is set by the problem. no there can be multiple henchman at any seniority level, see the notes section for examples

the-vampiire added a commit that referenced this issue Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest wizard apprentice if you solve these you are on your way to being a wizard
Projects
None yet
Development

No branches or pull requests

2 participants