From: Mart Lubbers Date: Thu, 17 Dec 2020 13:36:17 +0000 (+0100) Subject: 13, blurp X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0fc171307237eef8784b6543c0d5cc6c3e454502;p=aoc20.git 13, blurp --- 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)