2020-12-08 22:16:33 -06:00
|
|
|
#SingleInstance, Force
|
|
|
|
loc := A_ScriptDir "\data5.txt"
|
|
|
|
file := FileOpen(loc, "r")
|
2020-12-09 12:11:32 -06:00
|
|
|
binID := []
|
|
|
|
decID := []
|
|
|
|
|
2020-12-08 22:16:33 -06:00
|
|
|
|
|
|
|
dialog(str){
|
|
|
|
MsgBox, 1,, %str%
|
|
|
|
IfMsgBox, Cancel
|
|
|
|
Run, day5.ahk
|
|
|
|
}
|
|
|
|
|
|
|
|
while !(file.AtEOF){
|
|
|
|
line := file.ReadLine()
|
|
|
|
line := RegExReplace(line, "F|L", "0")
|
|
|
|
line := RegExReplace(line, "B|R", "1")
|
2020-12-09 12:11:32 -06:00
|
|
|
binID.Push(line)
|
|
|
|
decID.Push(Dec(line))
|
2020-12-08 22:16:33 -06:00
|
|
|
}
|
2020-12-09 12:11:32 -06:00
|
|
|
SortArray(binID, "D")
|
|
|
|
SortArray(decID, "D")
|
|
|
|
dialog("Part 1: " binID[binID.MinIndex()] "`n" decID[decID.MinIndex()])
|
2020-12-08 22:16:33 -06:00
|
|
|
|
2020-12-09 12:11:32 -06:00
|
|
|
Dec(x){
|
|
|
|
b:=StrLen(x),r:=0
|
|
|
|
loop,parse,x
|
|
|
|
r|=A_LoopField<<--b
|
|
|
|
return r
|
2020-12-08 22:16:33 -06:00
|
|
|
}
|
|
|
|
|
2020-12-09 12:11:32 -06:00
|
|
|
; the below is from https://sites.google.com/site/ahkref/custom-functions/sortarray, thank you A_Samurai
|
|
|
|
SortArray(Array, Order="A") {
|
|
|
|
;Order A: Ascending, D: Descending, R: Reverse
|
|
|
|
MaxIndex := ObjMaxIndex(Array)
|
|
|
|
If (Order = "R") {
|
|
|
|
count := 0
|
|
|
|
Loop, % MaxIndex
|
|
|
|
ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
|
|
|
|
Return
|
|
|
|
}
|
|
|
|
Partitions := "|" ObjMinIndex(Array) "," MaxIndex
|
|
|
|
Loop {
|
|
|
|
comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
|
|
|
|
spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
|
|
|
|
if (Order = "A") {
|
|
|
|
Loop, % epos - spos {
|
|
|
|
if (Array[pivot] > Array[A_Index+spos])
|
|
|
|
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Loop, % epos - spos {
|
|
|
|
if (Array[pivot] < Array[A_Index+spos])
|
|
|
|
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
|
|
|
|
if (pivot - spos) > 1 ;if more than one elements
|
|
|
|
Partitions .= "|" spos "," pivot-1 ;the left partition
|
|
|
|
if (epos - pivot) > 1 ;if more than one elements
|
|
|
|
Partitions .= "|" pivot+1 "," epos ;the right partition
|
|
|
|
} Until !Partitions
|
|
|
|
}
|