Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. I always thought that my old friend John was rather richer than he looked, but I never knew exactly how much money he actually had. One day (as I was plying him with questions) he said:
  2.  
  3. "Imagine I have between m and n Zloty..." (or did he say Quetzal? I can't remember!)
  4. "If I were to buy 9 cars costing c each, I'd only have 1 Zloty (or was it Meticals?) left."
  5. "And if I were to buy 7 boats at b each, I'd only have 2 Ringglets (or was it Zloty?) left."
  6. Could you tell me in each possible case:
  7.  
  8. how much money f he could possibly have ?
  9. the cost c of a car?
  10. the cost b of a boat?
  11. So, I will have a better idea about his fortune. Note that if m-n is big enough, you might have a lot of possible answers.
  12.  
  13. Each answer should be given as ["M: f", "B: b", "C: c"] and all the answers as [ ["M: f", "B: b", "C: c"], ... ]. "M" stands for money, "B" for boats, "C" for cars.
  14.  
  15. Note: m, n, f, b, c are positive integers, where 0 <= m <= n or m >= n >= 0. m and n are inclusive.
  16.  
  17. Examples:
  18. howmuch(1, 100) => [["M: 37", "B: 5", "C: 4"], ["M: 100", "B: 14", "C: 11"]]
  19. howmuch(1000, 1100) => [["M: 1045", "B: 149", "C: 116"]]
  20. howmuch(10000, 9950) => [["M: 9991", "B: 1427", "C: 1110"]]
  21. howmuch(0, 200) => [["M: 37", "B: 5", "C: 4"], ["M: 100", "B: 14", "C: 11"], ["M: 163", "B: 23", "C: 18"]]
  22. Explanation of the results for howmuch(1, 100):
  23.  
  24. In the first answer his possible fortune is 37:
  25. so he can buy 7 boats each worth 5: 37 - 7 * 5 = 2
  26. or he can buy 9 cars worth 4 each: 37 - 9 * 4 = 1
  27. The second possible answer is 100:
  28. he can buy 7 boats each worth 14: 100 - 7 * 14 = 2
  29. or he can buy 9 cars worth 11: 100 - 9 * 11 = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement