Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.99 KB | None | 0 0
  1. Lovely Lucky LAMBs
  2. ==================
  3.  
  4. 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!
  5.  
  6. 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!
  7.  
  8. There are 4 key rules which you must follow in order to avoid a revolt:
  9.    1. The most junior henchman (with the least seniority) gets exactly 1 LAMB.  (There will always be at least 1 henchman on a team.)
  10.    2. A henchman will revolt if the person who ranks immediately above them gets more than double the number of LAMBs they do.
  11.    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.)
  12.    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.
  13.  
  14. 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.
  15.  
  16. Write a function called solution(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.  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, solution(10) should return 4-3 = 1.
  17.  
  18. To keep things interesting, Commander Lambda varies the sizes of the Lucky LAMB payouts. You can expect total_lambs to always be a positive integer less than 1 billion (10 ^ 9).
  19.  
  20. Languages
  21. =========
  22.  
  23. To provide a Python solution, edit solution.py
  24. To provide a Java solution, edit Solution.java
  25.  
  26. Test cases
  27. ==========
  28. Your code should pass the following test cases.
  29. Note that it may also be run against hidden test cases not shown here.
  30.  
  31. -- Python cases --
  32. Input:
  33. solution.solution(143)
  34. Output:
  35.    3
  36.  
  37. Input:
  38. solution.solution(10)
  39. Output:
  40.    1
  41.  
  42. -- Java cases --
  43. Input:
  44. Solution.solution(143)
  45. Output:
  46.    3
  47.  
  48. Input:
  49. Solution.solution(10)
  50. Output:
  51.    1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement