Skip to content

Instantly share code, notes, and snippets.

@jaguilar
Created January 10, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaguilar/b62fd28830a67ff2ae9176e36665ceb8 to your computer and use it in GitHub Desktop.
Save jaguilar/b62fd28830a67ff2ae9176e36665ceb8 to your computer and use it in GitHub Desktop.
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