39 lines
1.3 KiB
AutoHotkey
39 lines
1.3 KiB
AutoHotkey
#SingleInstance, Force
|
|
loc := A_ScriptDir "\data4.txt"
|
|
file := FileOpen(loc, "r")
|
|
i++
|
|
data := {}
|
|
byrR := "\A19[2-9]\d\Z|\A200[0-2]\Z"
|
|
iyrR := "\A201\d\Z|\A2020\Z"
|
|
eyrR := "\A202\d\Z|\A2030\Z"
|
|
hgtR := "\A(1[5-8]\d|19[0-3])cm\Z|\A(59|6\d|7[0-6])in\Z"
|
|
hclR := "\A#(\d|[a-z]){6}\Z"
|
|
eclR := "\A(amb)\Z|\A(blu)\Z|\A(brn)\Z|\A(gry)\Z|\A(grn)\Z|\A(hzl)\Z|\A(oth)\Z"
|
|
pidR := "\A\d{9}\Z"
|
|
|
|
while !(file.AtEOF){
|
|
line := file.ReadLine()
|
|
If (line ~= "^(\s)"){
|
|
i++
|
|
} Else {
|
|
For _, pair in StrSplit(line, A_Space, " `n")
|
|
If (sep := InStr(pair, ":"))
|
|
data[i, SubStr(pair, 1, sep - 1)] := SubStr(pair, sep + 1)
|
|
}
|
|
|
|
If (data[i].byr != "" && data[i].iyr != "" && data[i].eyr != "" && data[i].hgt != "" && data[i].hcl != "" && data[i].ecl != "" && data[i].pid != "")
|
|
p1++
|
|
If (data[i].byr ~= byrR && data[i].iyr ~= iyrR && data[i].eyr ~= eyrR && data[i].hgt ~= hgtR && data[i].hcl ~= hclR && data[i].ecl ~= eclR && data[i].pid ~= pidR)
|
|
p2++
|
|
}
|
|
|
|
dialog("Part 1:`t" p1 "`nPart 2:`t" p2)
|
|
|
|
dialog(str){
|
|
MsgBox, 1,, %str%
|
|
IfMsgBox, Cancel
|
|
Run, day4.ahk
|
|
}
|
|
|
|
; dialog("Number: " i "`nbyr:`t" data[i].byr "`niyr:`t" data[i].iyr "`neyr:`t" data[i].eyr "`necl:`t" data[i].ecl "`nhgt:`t" data[i].hgt "`nhcl:`t" data[i].hcl "`ncid:`t" data[i].cid "`npid:`t" data[i].pid "`n`nTotal valid so far:`t" p1)
|