From de37379cc03b62ef0e3cab2b2e5b5006bf9f3925 Mon Sep 17 00:00:00 2001 From: Colin Diem Date: Sun, 4 Dec 2022 18:45:41 -0500 Subject: [PATCH] completes day2, starts day3. --- day2/{main.py => part1.py} | 0 day2/part2.py | 74 ++++++++++++++++++++++++++++++++++++++ day3/main.py | 15 ++++++++ day3/test.txt | 6 ++++ 4 files changed, 95 insertions(+) rename day2/{main.py => part1.py} (100%) create mode 100644 day2/part2.py create mode 100644 day3/main.py create mode 100644 day3/test.txt diff --git a/day2/main.py b/day2/part1.py similarity index 100% rename from day2/main.py rename to day2/part1.py diff --git a/day2/part2.py b/day2/part2.py new file mode 100644 index 0000000..a2c9cfb --- /dev/null +++ b/day2/part2.py @@ -0,0 +1,74 @@ +import datetime +print(datetime.datetime.now()) +input = open("./input.txt", "r") + +gameResult = { + "win": 6, + "tie": 3, + "lose": 0 +} + +throws = { + "rock": 1, + "paper": 2, + "scissors": 3 +} + +desiredOutcomeMap = { + "X": "lose", + "Y": "tie", + "Z": "win" +} + +opponentThrowMap = { + "A": "rock", + "B": "paper", + "C": "scissors" +} + +def determineThrow(opponent, desiredOutcome): + if (opponent == "rock"): + if (desiredOutcome == "win"): + return "paper" + if (desiredOutcome == "lose"): + return "scissors" + return "rock" + if (opponent == "scissors"): + if (desiredOutcome == "win"): + return "rock" + if (desiredOutcome == "lose"): + return "paper" + return "scissors" + if (desiredOutcome == "win"): + return "scissors" + if (desiredOutcome == "lose"): + return "rock" + return "paper" + +total = 0 + +def determineWinner(opponent, self): + if (opponent == self): + return "tie" + if (throws[opponent] == throws["rock"]): + if (throws[self] == throws["paper"]): + return "win" + if (throws[opponent] == throws["paper"]): + if (throws[self] == throws["scissors"]): + return "win" + if (throws[opponent] == throws["scissors"]): + if (throws[self] == throws["rock"]): + return "win" + return "lose" + +def calculateScore(throw, result): + return gameResult[result] + throws[throw] + +for line in input: + opponentThrow = opponentThrowMap[line[0]] + myThrow = determineThrow(opponentThrow, desiredOutcomeMap[line[2]]) + game = determineWinner(opponentThrow, myThrow) + total += calculateScore(myThrow, game) + +print(total) +print(datetime.datetime.now()) \ No newline at end of file diff --git a/day3/main.py b/day3/main.py new file mode 100644 index 0000000..eae1062 --- /dev/null +++ b/day3/main.py @@ -0,0 +1,15 @@ +input = open("./test.txt", "r") + +total = 0 + +for line in input: + total += total + lineLength = len(line) - 1 + lineLength = int(lineLength / 2) + print(lineLength) + pack1 = line[:lineLength] + pack2 = line[lineLength:] + print(pack1) + print(pack2) + +print(total) \ No newline at end of file diff --git a/day3/test.txt b/day3/test.txt new file mode 100644 index 0000000..9919ffa --- /dev/null +++ b/day3/test.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw \ No newline at end of file