Initial setup

This commit is contained in:
2020-12-06 23:33:55 +01:00
parent 719c643b03
commit e011ff8444
13 changed files with 2817 additions and 0 deletions

10
Scripts/Day1_1.py Normal file
View File

@@ -0,0 +1,10 @@
f = open("Ressources/NumsDay1.txt", 'r')
nums = f.readlines()
nums = [int(i) for i in nums]
for i in nums:
for j in nums:
if i + j == 2020:
print(i*j)
break

11
Scripts/Day1_2.py Normal file
View File

@@ -0,0 +1,11 @@
f = open("Ressources/NumsDay1.txt", 'r')
nums = f.readlines()
nums = [int(i) for i in nums]
for i in nums:
for j in nums:
for k in nums:
if i + j + k == 2020:
print(i*j*k)
break

21
Scripts/Day2_1.py Normal file
View File

@@ -0,0 +1,21 @@
f = open("Ressources/InputDay2.txt", 'r')
input = f.readlines()
limiters = []
chars = []
passwords = []
for i in input:
limiter, char, password = i.split(" ")
limiters.append(limiter)
chars.append(char[0])
passwords.append(password.strip())
validPasswords = 0
for (password, char, limiter) in zip(passwords, chars, limiters):
if int(limiter.split('-')[0]) <= password.count(char) <= int(limiter.split('-')[1]):
validPasswords += 1
print(validPasswords)

21
Scripts/Day2_2 copy.py Normal file
View File

@@ -0,0 +1,21 @@
f = open("Ressources/InputDay2.txt", 'r')
input = f.readlines()
indexes = []
chars = []
passwords = []
for i in input:
index, char, password = i.split(" ")
indexes.append(index)
chars.append(char[0])
passwords.append(password.strip())
validPasswords = 0
for (password, char, index) in zip(passwords, chars, indexes):
if (password[int(index.split('-')[0])-1] == char) ^ (password[int(index.split('-')[1])-1] == char):
validPasswords += 1
print(validPasswords)

23
Scripts/Day3_1.py Normal file
View File

@@ -0,0 +1,23 @@
xPosition = 0
treesEncounterd = 0
def makeStep():
global xPosition
if xPosition+3 >= map[0].__len__():
xPosition = (xPosition+3) - map[0].__len__()
else :
xPosition += 3
f = open("Ressources/InputDay3.txt", 'r')
map = [f.strip() for f in f.readlines()]
deepestLevel = map.__len__()
for i in range(1,deepestLevel):
makeStep()
if map[i][xPosition] == '#':
treesEncounterd += 1
print(treesEncounterd)

25
Scripts/Day3_2.py Normal file
View File

@@ -0,0 +1,25 @@
import numpy
f = open("Ressources/InputDay3.txt", 'r')
map = [f.replace('\n', '') for f in f.readlines()]
rightSteps = [1,3,5,7,1]
downSteps = [1,1,1,1,2]
treesEncounterd = []
x_pos = 0
counter = 0
for right, down in zip(rightSteps, downSteps):
trees = 0
x_pos = 0
for y_pos in range (0, len(map), down):
if map[y_pos][x_pos] == '#':
trees += 1
x_pos = (x_pos + right) % len(map[0])
treesEncounterd.append(trees)
print (numpy.prod(treesEncounterd))

27
Scripts/Day4_1.py Normal file
View File

@@ -0,0 +1,27 @@
f = open("Ressources/InputDay4.txt", 'r')
input = ""
for line in f:
if not line.isspace():
input += line
else:
input += 'ü'
input = input.replace("\n", "")
passports = input.split('ü')
requiered = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
valid = 0
for passport in passports:
matches = 0
for requierdInfo in requiered:
if requierdInfo in passport:
matches += 1
if matches == len(requiered):
valid += 1
print(valid)

41
Scripts/Day4_2.py Normal file
View File

@@ -0,0 +1,41 @@
f = open("Ressources/Test.txt", 'r')
input = ""
for line in f:
if not line.isspace():
input += line
else:
input += 'ü'
input = input.replace("\n", "")
passports = input.split('ü')
requiered = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
minValueCm = ["1920", "2010", "2020", "150", "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$", "amb blu brn gry grn hzl oth", "^0\d{8}$"]
maxValueIn = ["2002", "2020", "2030", "193", "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$", "amb blu brn gry grn hzl oth", "^0\d{8}$"]
minValueIn = ["1920", "2010", "2020", "59", "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$", "amb blu brn gry grn hzl oth", "^0\d{8}$"]
maxValueIn = ["2002", "2020", "2030", "76", "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$", "amb blu brn gry grn hzl oth", "^0\d{8}$"]
minValueCmDict = dict(zip(requiered, minValueCm))
maxValueInDict = dict(zip(requiered, maxValueIn))
minValueInDict = dict(zip(requiered, minValueIn))
maxValueInDict = dict(zip(requiered, maxValueIn))
valid = 0
for passport in passports:
matches = 0
keys = passport.split
# for requierdInfo in requiered:
# if requierdInfo in passport:
# matches += 1
# if matches == len(requiered):
# valid += 1
print(valid)