From bd144cb3f8d4ee33ad0622b7f7812701f91eacc8 Mon Sep 17 00:00:00 2001 From: David Daily Date: Wed, 9 Dec 2020 13:08:21 -0600 Subject: [PATCH] final solution --- 2020/day5.ahk | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/2020/day5.ahk b/2020/day5.ahk index 3de04a0..41989c1 100644 --- a/2020/day5.ahk +++ b/2020/day5.ahk @@ -4,6 +4,28 @@ file := FileOpen(loc, "r") binID := [] decID := [] +while !(file.AtEOF){ + line := file.ReadLine() + RegExMatch(line, "\S*", line) + line := RegExReplace(line, "F|L", "0") + line := RegExReplace(line, "B|R", "1") + binID.Push(line) + decID.Push(Dec(line)) +} +SortArray(binID) +SortArray(decID) + +dialog("Part 1: " binID[binID.MaxIndex()] " | " decID[decID.MaxIndex()]) + +next := decID[decID.MinIndex()] + +for k, v in decID + If (v = next){ + next := v + 1 + } Else { + dialog("Part 2: " v - 1) + ExitApp + } dialog(str){ MsgBox, 1,, %str% @@ -11,17 +33,6 @@ dialog(str){ Run, day5.ahk } -while !(file.AtEOF){ - line := file.ReadLine() - line := RegExReplace(line, "F|L", "0") - line := RegExReplace(line, "B|R", "1") - binID.Push(line) - decID.Push(Dec(line)) -} -SortArray(binID, "D") -SortArray(decID, "D") -dialog("Part 1: " binID[binID.MinIndex()] "`n" decID[decID.MinIndex()]) - Dec(x){ b:=StrLen(x),r:=0 loop,parse,x