From 0fc171307237eef8784b6543c0d5cc6c3e454502 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 17 Dec 2020 14:36:17 +0100 Subject: [PATCH] 13, blurp --- 13/one.icl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 13/one.icl diff --git a/13/one.icl b/13/one.icl new file mode 100644 index 0000000..288cf0f --- /dev/null +++ b/13/one.icl @@ -0,0 +1,22 @@ +module one + +import StdEnv +import Data.Func + +inp :: (Int, [?Int]) +inp = (1000067, [?Just 17,?None,?None,?None,?None,?None,?None,?None,?None,?None,?None,?Just 37,?None,?None,?None,?None,?None,?Just 439,?None,?Just 29,?None,?None,?None,?None,?None,?None,?None,?None,?None,?None,?Just 13,?None,?None,?None,?None,?None,?None,?None,?None,?None,?Just 23,?None,?None,?None,?None,?None,?None,?None,?Just 787,?None,?None,?None,?None,?None,?None,?None,?None,?None,?Just 41,?None,?None,?None,?None,?None,?None,?None,?None,?Just 19]) + +Start = (one inp, two inp) + +one (cur, bs) = uncurry (*) $ hd $ sort [(b - cur rem b, b)\\(?Just b)<-bs] + +two (start, busses) + # b=:[(_, mbo):_] = sortBy (>) [(b, i)\\(?Just b)<-busses & i<-[0..]] + = snd (foldl (crt mbo) (1, start) b) - mbo +where + crt max_bus_offset (max_bus, startpoint) (next_biggest_bus, next_offset) + # startpoint = while + (\sp->(sp+next_offset-max_bus_offset) rem next_biggest_bus <> 0) + (\sp->sp + max_bus) + startpoint + = (max_bus*next_biggest_bus, startpoint) -- 2.20.1