Created
January 10, 2019 15:45
-
-
Save jaguilar/b62fd28830a67ff2ae9176e36665ceb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc strat1(guards: Table[int, GuardSchedule]) = | |
var bestGuard = -1 | |
for k, v in guards.pairs: | |
if bestGuard != -1: | |
let oldSum = foldl(guards[bestGuard], a + b) | |
let newSum = foldl(v, a + b) | |
if newSum <= oldSum: | |
continue | |
bestGuard = k | |
echo "Guard #", bestGuard, " slept the most" | |
let bestGuardSchedule = guards[bestGuard] | |
var bestMinute = 0 | |
for i in 1..59: | |
if bestGuardSchedule[i] > bestGuardSchedule[bestMinute]: bestMinute = i | |
echo "This guard slept the most in minute ", bestMinute | |
echo bestGuard * bestMinute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment