diff options
-rw-r--r-- | problem700.ijs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/problem700.ijs b/problem700.ijs new file mode 100644 index 0000000..c84b342 --- /dev/null +++ b/problem700.ijs @@ -0,0 +1,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 |