Ok i'm done DRYing
This commit is contained in:
parent
25e1c51fa4
commit
da61289cbb
|
@ -1,17 +1,9 @@
|
||||||
import ./common, std/[strutils, sequtils, strformat, sugar]
|
import ./common, std/[strutils, sequtils, strformat, sugar]
|
||||||
|
|
||||||
proc crabFuel(c: seq[int]): int =
|
proc crabFuel(c: seq[int], f = (n: int) => n): int =
|
||||||
(0..c.foldl(max(a, b))).toSeq()
|
toSeq((1..c.foldl(max(a, b)))).reduce((r,t) => min(c.foldl(a + f(abs(b - t)), 0), r), high(int))
|
||||||
.reduce((r,t) => min(c.foldl(a + abs(b - t), 0), r), high(int))
|
|
||||||
|
|
||||||
proc triangleNumber(n: int): int = int((n * (n + 1)) / 2)
|
doDay(7, (n) => n.loadInputText().split(',').map(parseInt),
|
||||||
|
(n) => n.crabFuel(),
|
||||||
proc crabMoreFuel(c: seq[int]): int =
|
(n) => n.crabFuel((c: int) => (c * (c + 1)) div 2),
|
||||||
(0..c.foldl(max(a, b))).toSeq()
|
|
||||||
.reduce((r,t) => min(c.foldl(a + abs(b - t).triangleNumber(), 0), r), high(int))
|
|
||||||
|
|
||||||
doDay(7,
|
|
||||||
(day) => day.loadInputText().split(',').map(parseInt),
|
|
||||||
crabFuel,
|
|
||||||
crabMoreFuel,
|
|
||||||
@[16,1,2,0,4,2,7,1,2,14], 37, 168)
|
@[16,1,2,0,4,2,7,1,2,14], 37, 168)
|
||||||
|
|
Loading…
Reference in a new issue