Day 2
This commit is contained in:
parent
374dfcbc1d
commit
d48ccb2d2e
19
2020/day2.ahk
Normal file
19
2020/day2.ahk
Normal file
@ -0,0 +1,19 @@
|
||||
#SingleInstance, Force
|
||||
loc := A_ScriptDir "\data2.txt"
|
||||
file := FileOpen(loc, "r")
|
||||
|
||||
Loop {
|
||||
If (file.AtEOF)
|
||||
Break
|
||||
data := StrSplit(file.ReadLine(), [A_Tab, A_Space, "-"], " `t:-")
|
||||
; 1:first number 2:second number 3:letter 4:password
|
||||
reg := "^[^" data[3] "]*(" data[3] "[^" data[3] "]*){" data[1] "," data[2] "}$"
|
||||
|
||||
StrReplace(data[4],data[3],,test) ; String Replace to get # of LETTER
|
||||
If (test>=data[1] AND test<=data[2]) ; Check if # of LETTER is within the bounds
|
||||
p1++
|
||||
If ((subStr(data[4], data[1], 1) == data[3])^(subStr(data[4], data[2], 1) == data[3])) ; Please don't make me explain this one
|
||||
p2++
|
||||
}
|
||||
file.Close()
|
||||
MsgBox % "Part 1: " p1 "`nPart 2: " p2
|
Loading…
Reference in New Issue
Block a user