mirror of
https://github.com/peter-tanner/advent-of-code-2020.git
synced 2024-11-30 10:50:17 +08:00
first three days of advent of code :)
This commit is contained in:
commit
a0f6b8594f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
data.txt
|
||||
input
|
6
1/a.py
Normal file
6
1/a.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
lines = open("data.txt").read().splitlines()
|
||||
|
||||
for u in lines:
|
||||
for v in lines:
|
||||
if int(u)+int(v) == 2020:
|
||||
print(int(u)*int(v))
|
9
1/b.py
Normal file
9
1/b.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
lines = open("data.txt").read().splitlines()
|
||||
|
||||
numbers = []
|
||||
|
||||
for u in lines:
|
||||
for v in lines:
|
||||
for w in lines:
|
||||
if int(u)+int(v)+int(w) == 2020:
|
||||
print(int(u)*int(v)*int(w))
|
11
2/a.py
Normal file
11
2/a.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
lines = open("input").read().splitlines()
|
||||
|
||||
count = 0
|
||||
for line in lines:
|
||||
line = line.replace('-',' ').replace(':','').split(' ')
|
||||
# print(line)
|
||||
# print(line[3].count(line[2]))
|
||||
if int(line[0]) <= line[3].count(line[2]) <= int(line[1]):
|
||||
count = count + 1
|
||||
|
||||
print(count)
|
18
2/b.py
Normal file
18
2/b.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
lines = open("input").read().splitlines()
|
||||
|
||||
count = 0
|
||||
for line in lines:
|
||||
line = line.replace('-',' ').replace(':','').split(' ')
|
||||
strarr = list(line[3])
|
||||
# print(strarr)
|
||||
v = 0
|
||||
if strarr[int(line[0])-1] == line[2]:
|
||||
v = v + 1
|
||||
if strarr[int(line[1])-1] == line[2]:
|
||||
v = v + 1
|
||||
if v == 1:
|
||||
count = count + 1
|
||||
# print(line)
|
||||
# print(line[3].count(line[2]))
|
||||
|
||||
print(count)
|
19
3/a.py
Normal file
19
3/a.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
lines = open('input').read().splitlines()
|
||||
period = 31 #in chars
|
||||
|
||||
mat = []
|
||||
for line in lines:
|
||||
mat_row = [1 if x == '#' else 0 for x in list(line)]
|
||||
mat.append(mat_row)
|
||||
|
||||
count = 0
|
||||
j_ = 0
|
||||
for i in range(0, len(mat)):
|
||||
print(mat[i])
|
||||
j = j_ % period
|
||||
j_ += 3
|
||||
|
||||
if (mat[i][j] == 1):
|
||||
count += 1
|
||||
print(count)
|
38
3/b.py
Normal file
38
3/b.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
lines = open('input').read().splitlines()
|
||||
period = 31 #in chars
|
||||
|
||||
mat = []
|
||||
for line in lines:
|
||||
mat_row = [1 if x == '#' else 0 for x in list(line)]
|
||||
mat.append(mat_row)
|
||||
|
||||
|
||||
ld = [
|
||||
[1,1],
|
||||
[3,1],
|
||||
[5,1],
|
||||
[7,1],
|
||||
[1,2]
|
||||
]
|
||||
|
||||
lcount = []
|
||||
for d in ld:
|
||||
dx = d[0]
|
||||
dy = d[1]
|
||||
j_ = 0
|
||||
count = 0
|
||||
for i in range(0, len(mat), dy):
|
||||
j = j_ % period
|
||||
j_ += dx
|
||||
|
||||
if (mat[i][j] == 1):
|
||||
count += 1
|
||||
lcount.append(count)
|
||||
|
||||
print(lcount)
|
||||
ans = 1
|
||||
for r in lcount:
|
||||
ans = r*ans
|
||||
|
||||
print(ans)
|
Loading…
Reference in New Issue
Block a user