Finished 2015-12-03 part 1+2

This commit is contained in:
FrederikBaerentsen 2023-12-04 18:03:20 +01:00
parent a9caf0f577
commit d3682fd762
6 changed files with 101 additions and 0 deletions

1
2015/day3/input Normal file

File diff suppressed because one or more lines are too long

41
2015/day3/part1.py Normal file
View File

@ -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)

56
2015/day3/part2.py Normal file
View File

@ -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)

1
2015/day3/test1 Normal file
View File

@ -0,0 +1 @@
^v

1
2015/day3/test2 Normal file
View File

@ -0,0 +1 @@
^>v<

1
2015/day3/test3 Normal file
View File

@ -0,0 +1 @@
^v^v^v^v^v