You are the best and most famous hero of the area. Lately there have been rumors that a Hydra has been hanging out in a nearby ravine. Being the brave and virtuous hero that you are you figure you'll go check it out sometime later today.
The problem with hydrae is that every time you try to cut off their heads some new ones grow back. Luckily for you you have swords that can cut off multiple heads at once. But there's a catch, if the hydra has less heads than your sword cuts, you wont be able to attack the hydra. When the hydra has exactly zero heads, you have killed it.
There is also a special sword called The Bisector that will cut off half of the Hydra's heads, but only if the number of heads is even. The Bisector cannot be used at all when the number of heads is odd. This is different from cutting off zero heads.
So you have decided you will write a computer program to figure out the best way to slay the hydra.
Task
You will be given as input
- the number of heads the Hydra starts with
- the number of heads the Hydra regrows each turn
- a list of swords available for use each (each either is a bisector or cuts a fixed number of heads each turn)
You should output a list of moves that will kill the hydra in the least number of turns possible. If there is no way to kill the hydra you must output some other value indicating so (and empty list is fine if your language is strongly typed). If there are multiple optimal ways to kill the hydra you may output any one of them or all of them.
This is a code-golf question so answers will be scored in bytes, with fewer bytes being better.
Test Cases
More available upon request
5 heads, 9 each turn, [-1,-2,-5] -> [-5]
12 heads, 1 each turn, [/2,-1] -> No solution
8 heads, 2 each turn, [-9, -1] -> [-1,-9]
3 heads, 23 each turn, [/2,-1,-26] -> [-1,-1,-26,-26,-26,-26,-26,-26,-26,-26]
16 heads, 1 each turn, [/2, 4, 2] -> [/2,-4,/2,-4]
This question is a simplified version of the main mechanic of HydraSlayer. If you like this type of puzzle I recommend checking it out, its pretty fun. I do not have any affiliation with the game.
[/2, -2, /2, -2, -4]
also works. \$\endgroup\$