+/foobar
google programming puzzles
git clone https://git.julia.blue/+/foobar
2e1d345
master
1Fuel Injection Perfection 2========================= 3 4Commander Lambda has asked for your help to refine the automatic quantum antimatter fuel injection system for her LAMBCHOP doomsday device. It's a great chance for you to get a closer look at the LAMBCHOP - and maybe sneak in a bit of sabotage while you're at it - so you took the job gladly. 5 6Quantum antimatter fuel comes in small pellets, which is convenient since the many moving parts of the LAMBCHOP each need to be fed fuel one pellet at a time. However, minions dump pellets in bulk into the fuel intake. You need to figure out the most efficient way to sort and shift the pellets down to a single pellet at a time. 7 8The fuel control mechanisms have three operations: 9 101) Add one fuel pellet 112) Remove one fuel pellet 123) Divide the entire group of fuel pellets by 2 (due to the destructive energy released when a quantum antimatter pellet is cut in half, the safety controls will only allow this to happen if there is an even number of pellets) 13 14Write a function called answer(n) which takes a positive integer as a string and returns the minimum number of operations needed to transform the number of pellets to 1. The fuel intake control panel can only display a number up to 309 digits long, so there won't ever be more pellets than you can express in that many digits. 15 16For example: 17answer(4) returns 2: 4 -> 2 -> 1 18answer(15) returns 5: 15 -> 16 -> 8 -> 4 -> 2 -> 1 19 20 21Languages 22========= 23 24To provide a Python solution, edit solution.py 25To provide a Java solution, edit solution.java 26 27Test cases 28========== 29 30Inputs: 31 (string) n = "4" 32Output: 33 (int) 2 34 35Inputs: 36 (string) n = "15" 37Output: 38 (int) 5 39