diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/day2/day2.py b/day2/day2.py index 5e199fe114894bf3ac71ed5a7742b466f8518061..8dc4eab533d5480bb0c95cdb6c92cafe22a18515 100644 --- a/day2/day2.py +++ b/day2/day2.py @@ -1,4 +1,5 @@ -import ../util.py +import utilities as ut + # Day 2 - Part 1 def rock_paper_scissor_guide_result(): @@ -8,14 +9,13 @@ def rock_paper_scissor_guide_result(): "C X": 6, "C Y": 0, "C Z": 3} print(score_rps) score = 0 - with open("./input.dat") as file: - for line in file: - #print(line) - player1, player2 = line.split() - print(f"{player2}: {score_rps[player2]}") - score += score_rps[player2] - print(f"{line.strip()}: {game_rps[line.strip()]}") - score += game_rps[line.strip()] + for line in ut.read_line_by_line("input.dat"): + #print(line) + player1, player2 = line.split() + print(f"{player2}: {score_rps[player2]}") + score += score_rps[player2] + print(f"{line.strip()}: {game_rps[line.strip()]}") + score += game_rps[line.strip()] print(score) @@ -26,15 +26,15 @@ def rock_paper_scissor_guide_result2(): "B X": 1, "B Y": 2, "B Z": 3, "C X": 2, "C Y": 3, "C Z": 1} score = 0 - with open("./input.dat") as file: - for line in file: - player1, result = line.split() - print(f"{result}: {score_rps[result]}") - score += score_rps[result] - print(f"{line.strip()}: {game_rps[line.strip()]}") - score += game_rps[line.strip()] + for line in ut.read_line_by_line("input.dat"): + player1, result = line.split() + print(f"{result}: {score_rps[result]}") + score += score_rps[result] + print(f"{line.strip()}: {game_rps[line.strip()]}") + score += game_rps[line.strip()] print(score) + if __name__ == '__main__': #rock_paper_scissor_guide_result() rock_paper_scissor_guide_result2() diff --git a/utilities.py b/utilities.py new file mode 100644 index 0000000000000000000000000000000000000000..90745094cdd1f6966169d0c4298fc3984331fdae --- /dev/null +++ b/utilities.py @@ -0,0 +1,4 @@ +def read_line_by_line(filename): + with open(filename) as file: + for line in file: + yield line