summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2021-11-10 14:07:56 +0100
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2021-11-10 14:07:56 +0100
commita6c6adcd0736a91a4b95ca3974a3a8f34b379fc6 (patch)
treeff494816d11b6352f2f4eb7cacaba0e7ba8a0793
parent5771d30bbbca01d9905fcbda23beddffdf257790 (diff)
Problem 700
-rw-r--r--problem700.ijs22
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