From d48ccb2d2eb9c9d4aa453af1c6279a9fad059b43 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 2 Dec 2020 16:46:23 -0600 Subject: [PATCH] Day 2 --- 2020/day2.ahk | 19 +++++++++++++++++++ README.md | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 2020/day2.ahk diff --git a/2020/day2.ahk b/2020/day2.ahk new file mode 100644 index 0000000..1bd31cc --- /dev/null +++ b/2020/day2.ahk @@ -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 diff --git a/README.md b/README.md index bd3e161..7cc107b 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,6 @@ Advent of Code repo for stuff and things -[Advent of code website](https://adventofcode.com) \ No newline at end of file +[Advent of code website](https://adventofcode.com) + +Made with the help of the wonderful members of the AHK discord, cause I'm not that smaht and its only day 2.