blob: c84b3425d32c9b805a572dc6543cca968010a603 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
findCoins =: {{
NB. The distance from the start (0) either always increases, or we find a coin.
NB. This means we can calculate the new distance or next coin as y|lastCoin+offset
NB. If this value is less than the last coin, we have a new coin.
NB. If the value is larger than the last offset, we cannot have a new coin, so
NB. we increase the offset.
lastCoin =. x
offset =. x
coins =. lastCoin
while. lastCoin > 1 do.
tmpOffset =. y|lastCoin + offset
if. tmpOffset > offset do.
offset =. tmpOffset
elseif. tmpOffset < lastCoin do.
lastCoin =. tmpOffset
coins =. coins,lastCoin
end.
end.
coins
}}
problem700 =: +/ 1504170715041707 findCoins 4503599627370517
|