From: Ummon Date: Thu, 7 Dec 2017 09:14:50 +0000 (+0100) Subject: A bit less verbose X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=17e6f8045080f6bd75d376114246d34baf6df75e;p=advent_of_code_2017.git A bit less verbose --- diff --git a/AdventOfCode2017/Day7.fs b/AdventOfCode2017/Day7.fs index 869c0a9..1dd4728 100644 --- a/AdventOfCode2017/Day7.fs +++ b/AdventOfCode2017/Day7.fs @@ -44,11 +44,11 @@ let rec findUnbalanced (tower : Tower) : (Tower * int) option = let rec weight tower = tower.Weight + (tower.Above |> Seq.map weight |> Seq.sum) - let towersByWeight = tower.Above |> Seq.groupBy weight + let towersByWeight = tower.Above |> Seq.groupBy weight |> Seq.sortBy (snd >> Seq.length) if towersByWeight |> Seq.length > 1 then - let unbalanced = towersByWeight |> Seq.minBy (snd >> Seq.length) - let others = towersByWeight |> Seq.maxBy (snd >> Seq.length) + let unbalanced = towersByWeight |> Seq.item 0 + let others = towersByWeight |> Seq.item 1 let delta = fst others - fst unbalanced let unbalanced' = unbalanced |> snd |> Seq.head findUnbalanced unbalanced' |> Option.orElse (Some (unbalanced', unbalanced'.Weight + delta))