We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Mathematics
- Algebra
- Wet Shark and 42
- Discussions
Wet Shark and 42
Wet Shark and 42
Sort by
recency
|
19 Discussions
|
Please Login in order to post a comment
My Python code that passed all the test cases:
Am I the only person who read "divisible by 4 and/or 2 but not divisible by 42" as "(divisible by 4) and/or (divisible by 2 but not divisible by 42)" rather than "(divisible by 4 and/or 2) but (not divisible by 42)"? The second is apparently the correct interpretation (which cost a few Hackos to find out), but in that case the 4 is redundant. With the first interpretation, we don't get the "bonus" steps at the even multiples of 42 (which actually makes it a slightly more interesting question).
A little bit of rewording on this question might help clear up the potential confusion.
Python 3 Solution :
Assume that the shark has gone till he has reached the square number n and there, his strength has became 0 .
We know that n have to be divisible by 2 . The number of squares that are divisible by 2 and <= n is floor ( n/2 ) .
The number of squares divisible by 42 is floor ( n / 42 ) .
Here we want the number of squares divisible by 2 and not divisible by 42. Though we have floor (n/2) - floor(n/42) = s .
To solve this equation, you can write it in the form without floor functions (( n/2 + n/42 = s )) .
Then solve this equation. Let the answer to be x. First take the integer part of x.
Then set x as x-10. At last, run a loop from 0 to 20 and in each iteration, increment x.
After incrementing, check if x%2 ==0 and floor(x/2)-floor(x/42) == s .
The first x that satisfies the constraints is the answer.
Sorry for my bad English.
This can be thought of as a fenceposting issue.
That is, take some amount of s (try a few examples, like 21, 22, 40, 41, 42, 61 hint hint) and see how far you go.
Even further, think about how, if you have gotten to square 42, you get to square 44, what is the next multiple of 42 you'll reach? How much strength is required to get there from 44 (what square will you actually end on whith that exact amount of strength?). Does a pattern emerge after that? Remember, this is a math problem; doing it iteratively is wasteful.