From 5d5300a48e0ceb0ec3c6f29b8133c638884e663b Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Tue, 7 Dec 2021 07:51:46 +0100 Subject: [PATCH] switched rounding function --- Sources/07/07.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/07/07.swift b/Sources/07/07.swift index d66d5a0..ff93f04 100644 --- a/Sources/07/07.swift +++ b/Sources/07/07.swift @@ -30,8 +30,8 @@ struct Day07: Runnable { func runB(horizontalPositions: [Int]) { let average = Double(horizontalPositions.reduce(0, +)) / Double(horizontalPositions.count) - let roundedDown = Int(floor(average)) - let roundedUp = Int(ceil(average)) + let roundedDown = Int(average.rounded(.up)) + let roundedUp = Int(average.rounded(.down)) let fuelForRoundedDown = fuelConsumptionFor(horizontalPositions: horizontalPositions, toPosition: roundedDown) let fuelForRoundedUp = fuelConsumptionFor(horizontalPositions: horizontalPositions, toPosition: roundedUp) print(min(fuelForRoundedDown, fuelForRoundedUp))