Background
A Medusa have released a dangerous Hydra which is revived unless the exact number of heads it have is removed. The knights can remove a certain number of heads with each type of attack, and each attack causes a specific amount of heads to regrow. The knights have hired you to write a program or function that returns a truthy/falsey depending on whether the Hydra can be left with exactly zero heads after the next hit.
Note that this is fundamentally different from Become the Hydra Slayer. You are not supposed to figure out which attacks to use.
For example:
input: head = 2,
attacks = [1, 25, 62, 67],
growths = [15, 15, 34, 25],
hits = [5, 1, 0, 0]
output: TRUE
Explanation: The Hydra has 10 heads to start with, we have 4 different attacks
and for each attack, growth
gives us the number of heads that grows back. hits
gives us the number of times each attack is applied. So the number of heads the Hydra has after each attack is
2 -> 16 -> 30 -> 44 -> 58 -> 72 -> 62
Since 62
is a valid attack value (It lies in the attack list), we return True
since the Hydra will die on the next attack (be left with 0 heads). Note that the order for when the attacks are done is irrelevant.
2 -> 16 -> 6 -> 20 -> 34 -> 48 -> 62
Input
Any sort of logical way of feeding your program the attack, regrowth and hit values are acceptable. This includes, but is not limited to
- A list of tuples
(1, 15, 5), (25, 15, 1) (62, 34, 0) (67, 25, 0)
- Lists
2, [1, 25, 62, 67], [15, 15, 34, 25], [5, 1, 0, 0]
- Reading values from STDIN
1 15 1 15 1 15 1 15 1 15 25 15
- A file of values
Output
- Some form of truthy/falsey value in your language: 0/1, true/false, etc.
Assumption
You may assume that any input is valid. E.g every input will not overkill the Hydra and either result in a number of heads that is an attack value, or not.
Every list (if used) is to be assumed to be of equal lengths
Every attack value will always correspond to one regrowth value which never changes. these are not required to be unique
Every input will be a positive integer
Test Cases
The following 10 examples are all True
, and uses attacks=[1, 25, 62, 67]
, growths=[15, 15, 34, 25]
these are simply left out to be brief
1, [0, 0, 0, 0], -> True
2, [5, 1, 0, 0], -> True
3, [2, 3, 0, 0], -> True
4, [7, 4, 0, 0], -> True
5, [4, 6, 0, 0], -> True
6, [4, 0, 0, 0], -> True
7, [1, 2, 0, 0], -> True
8, [6, 3, 0, 0], -> True
9, [3, 5, 0, 0], -> True
10, [8, 6, 0, 0] -> True
25, [0, 0, 0, 0], -> True
67, [0, 0, 0, 0], -> True
62, [0, 0, 0, 0], -> True
98767893, [0, 1, 1, 2351614] -> True
The following examples are all False
, and uses attack=[1, 25, 62, 67]
, growth=[15, 15, 34, 25]
these are simply left out to be brief
65, [0, 3, 0, 0], -> False
66, [4, 5, 0, 0], -> False
68, [0, 2, 0, 0], -> False
69, [0, 1, 1, 0], -> False
70, [2, 5, 0, 0], -> False
71, [0, 0, 0, 1], -> False
72, [0, 0, 0, 0], -> False
73, [1, 2, 1, 0], -> False
74, [2, 3, 0, 0], -> False
75, [1, 5, 0, 0], -> False
98767893, [1, 1, 1, 2351614] -> False
This is a code-golf question so answers will be scored in bytes, with fewer bytes being better.