|> Array.map (fun line -> line.Split ([| ' '; '\t' |], StringSplitOptions.RemoveEmptyEntries) |> Array.map int)
let checksum1 (a : int[][]) =
- a
- |> Array.map (fun ns -> Array.max ns - Array.min ns)
- |> Array.sum
+ a |> Array.sumBy (fun ns -> Array.max ns - Array.min ns)
let checksum2 (a : int[][]) =
a
- |> Array.map (
+ |> Array.sumBy (
fun ns ->
seq {
for a in ns do
if a <> b && a % b = 0 then yield a / b
} |> Seq.head
)
- |> Array.sum
let neighborsSum (dic : Map<int * int, int>) (pos : int * int) =
let x, y = pos
[ for dx in -1 .. 1 do for dy in -1 .. 1 -> x + dx, y + dy ]
- |> List.map (fun (x, y) -> match dic |> Map.tryFind (x, y) with Some v -> v | None -> 0)
- |> List.sum
+ |> List.sumBy (fun (x, y) -> match dic |> Map.tryFind (x, y) with Some v -> v | None -> 0)
spiral
|> Seq.skip 1
// Returns the tower and its corrected weight.
let rec findUnbalanced (tower : Tower) : (Tower * int) option =
let rec weight tower =
- tower.Weight + (tower.Above |> Seq.map weight |> Seq.sum)
+ tower.Weight + (tower.Above |> Seq.sumBy weight)
match tower.Above |> List.ofSeq |> List.groupBy weight |> List.sortBy (snd >> List.length) with
| [ w1, [ unbalanced ]; w2, _ ] ->