commit a0f6b8594ffb645f61abf3f84353ed59c5bc489d Author: npc-strider Date: Thu Dec 3 14:39:42 2020 +0800 first three days of advent of code :) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28ed612 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data.txt +input diff --git a/1/a.py b/1/a.py new file mode 100644 index 0000000..a77eec7 --- /dev/null +++ b/1/a.py @@ -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)) \ No newline at end of file diff --git a/1/b.py b/1/b.py new file mode 100644 index 0000000..e3509cc --- /dev/null +++ b/1/b.py @@ -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)) \ No newline at end of file diff --git a/2/a.py b/2/a.py new file mode 100644 index 0000000..31b8091 --- /dev/null +++ b/2/a.py @@ -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) \ No newline at end of file diff --git a/2/b.py b/2/b.py new file mode 100644 index 0000000..f3bb85c --- /dev/null +++ b/2/b.py @@ -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) \ No newline at end of file diff --git a/3/a.py b/3/a.py new file mode 100644 index 0000000..34eb903 --- /dev/null +++ b/3/a.py @@ -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) \ No newline at end of file diff --git a/3/b.py b/3/b.py new file mode 100644 index 0000000..db5ac30 --- /dev/null +++ b/3/b.py @@ -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) \ No newline at end of file