From d3682fd7627b1f16c22846ef797b380fcea79bdd Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 4 Dec 2023 18:03:20 +0100 Subject: [PATCH] Finished 2015-12-03 part 1+2 --- 2015/day3/input | 1 + 2015/day3/part1.py | 41 +++++++++++++++++++++++++++++++++ 2015/day3/part2.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2015/day3/test1 | 1 + 2015/day3/test2 | 1 + 2015/day3/test3 | 1 + 6 files changed, 101 insertions(+) create mode 100644 2015/day3/input create mode 100644 2015/day3/part1.py create mode 100644 2015/day3/part2.py create mode 100644 2015/day3/test1 create mode 100644 2015/day3/test2 create mode 100644 2015/day3/test3 diff --git a/2015/day3/input b/2015/day3/input new file mode 100644 index 0000000..55f286f --- /dev/null +++ b/2015/day3/input @@ -0,0 +1 @@ +^><^>>>^<^v<<^<><^<^v>^vv<>v>>^^^v<<<^>^<^v<^>^v><<<^>><>v>v^<<^>^<<^^^>v>>v^^>^>vv>>^>>v^>^v>^<^^v>^>^^v^^>v^^v><^><^<<>v^<^<^vv^>>>v^v^>^<>^v<^^vv^>^<>^^<vv<>^>v<^>^v>v^>^v<>^><>>v^v<><>v^v>>>>v^^>^><^^<^>^v^v<>v<<<^<v^^^<^^^>v<^v>>>>>v<^^^^>v<^<>>>>>>v^vvvv^^^v<^v^>v><^>^v<<>>vv^>v>v^^>vv^<^vvv<>><>><><^^^^<^^^<^v>>v>^v^^^>v^^^v>>^v^^<^>>^>^<>>^^<>>^vv>v^<^>>>><><^^v<><<<<^^<>>^<>vv^<^>v^^><^v>^^>v<>^v^<>^vv^>vvv>v>^>^>>^>><>>>^^^^v^<>v^^>^<>v<^^v><^v><>^^^^^v^v>>^^v><<><^^^^><^>v>><<<^v>v^^>^v^<^^v>v<^<<>>^v<<>v<^v^>v^>^v<<v>v>>v>v^^v>^v^>>>><>^>v>^v^>>>>v^<<<>vvv>><^^>^<><^^<^v^v^<^^>^<^v^<<<^^v^v>>><>^^>vv<<^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<<^^v^^>v<<><^<>^^>^v<>v>><^^^vv^>^><>v^^>^v>^<<^v>^>>>>><^^^<>v>v^^<^v^>>v^<^>v^v>>>>^>>vv<>^<^v>v>v^v>^<>^>v<<>^<>>^<>>^<>v^><<>^v>>^^^^<<^v><>^<^>^^v><^^<^^v>v<<^>^>><<^^^vvv<<^vv<^^>v^^vv^<^^<<^^>>^^<v^>>v^^>v<^>^>vv>><v><^<^vv>^^v>^>v<<^vv><^^^^^^><<^>>>^v<>^^v<<<>><<<>^<<v^>^^^<^>^^^v<<>v^><<^^<<^v<<>^v>>vv>><<^v^^>v^v>^^v<><^^^<^^>v>^<>vvv^v^^^>v^^v<^>^^>>^v<><^><^<<^vv^<><<>v^vv^<<<^^>v<<>>>v<>v<><<^v>^^v>^^>v>^>^>v<>><>^>^>^vvvv<^^^^^v>v>><>^>^><>^^>v^^<<><^><<<<>v>^^>^v<<<>vvv>>v<^v>>v>v^<<<>^>^>^<>v<^^vv><^v<<^vv<^<<^^vv^^>vv<^>v>^^<^>v<<^^<^>^^^v^^>>v^vv^<^v>^<>^<^>>^<^v<>v><^^<><>^>v<^<^vv>><^v>^<>^^>^<><<>^<>><<>vvv^<<^^>>v<^>>vv>^v^^^v<>v<>><>^vv^>vv^ diff --git a/2015/day3/part1.py b/2015/day3/part1.py new file mode 100644 index 0000000..b154e22 --- /dev/null +++ b/2015/day3/part1.py @@ -0,0 +1,41 @@ +#!/bin/python3 + +import sys +from pprint import pprint + +input_f = sys.argv[1] + +result = 0 +arr = [] +l = 101 +for i in range(0,l): + arr.append([]) + for j in range(0,l): + arr[i].append('O') + +start=int((l-1)/2) + +X = start +Y = start + +with open(input_f) as file: + for line in file: + tmp = list(line.rstrip()) + arr[X][Y] = 'X' + for idx,i in enumerate(tmp): + if i == '^': + Y -= 1 + if i == '>': + X += 1 + if i == '<': + X -= 1 + if i == 'v': + Y += 1 + + arr[X][Y] = 'X' + +for idx,i in enumerate(arr): + for jdx,j in enumerate(i): + if arr[idx][jdx] == 'X': + result += 1 +print(result) diff --git a/2015/day3/part2.py b/2015/day3/part2.py new file mode 100644 index 0000000..340ae93 --- /dev/null +++ b/2015/day3/part2.py @@ -0,0 +1,56 @@ +#!/bin/python3 + +import sys +from pprint import pprint + +input_f = sys.argv[1] + +result = 0 +arr = [] +l = 101 +for i in range(0,l): + arr.append([]) + for j in range(0,l): + arr[i].append('O') + +start=int((l-1)/2) + +X = start +Y = start + +rX = start +rY = start + +with open(input_f) as file: + for line in file: + tmp = list(line.rstrip()) + arr[X][Y] = 'X' + arr[rX][rY] = 'X' + for idx,i in enumerate(tmp): + if idx % 2 == 0: + if i == '^': + Y -= 1 + if i == '>': + X += 1 + if i == '<': + X -= 1 + if i == 'v': + Y += 1 + else: + if i == '^': + rY -= 1 + if i == '>': + rX += 1 + if i == '<': + rX -= 1 + if i == 'v': + rY += 1 + + arr[X][Y] = 'X' + arr[rX][rY] = 'X' + +for idx,i in enumerate(arr): + for jdx,j in enumerate(i): + if arr[idx][jdx] == 'X': + result += 1 +print(result) diff --git a/2015/day3/test1 b/2015/day3/test1 new file mode 100644 index 0000000..a7e30de --- /dev/null +++ b/2015/day3/test1 @@ -0,0 +1 @@ +^v diff --git a/2015/day3/test2 b/2015/day3/test2 new file mode 100644 index 0000000..c59f4bf --- /dev/null +++ b/2015/day3/test2 @@ -0,0 +1 @@ +^>v< diff --git a/2015/day3/test3 b/2015/day3/test3 new file mode 100644 index 0000000..8a6e322 --- /dev/null +++ b/2015/day3/test3 @@ -0,0 +1 @@ +^v^v^v^v^v