diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index ada275d..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Update AoC Badges -on: - schedule: # run workflow based on schedule - - cron: '6 5 1-25 12 *' # from the 1. December till 25. December every day at 5:06am (avoid load at full hours) - - workflow_dispatch: # allow to manually start the workflow - - push: # (disabled) run on push, be carefull with this setting - # as the workflow should only be triggered at a rate lower than - # 4 times a hour to keep traffic on aoc site low -jobs: - update: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 # clones your repo - - - uses: joblo2213/aoc-badges-action@v3 - with: - userid: 1016386 # your user id, see setup on how to obtain - session: ${{ secrets.AOC_SESSION }} # secret containing session code, see setup on how to obtain - -# Optional inputs: -# -# year: 2021 # The year for which stats should be retrieved -# leaderboard: 'https://adventofcode.com/2020/leaderboard/private/view/00000.json' # The url of the leaderboard from witch the data is fetched. Typically your private leaderboard. -# file: 'README.md' # The file that contains the badges -# dayRegex: '(?<=https:\/\/img\.shields\.io\/badge\/day%20📅-)[0-9]+(?=-blue)' # Regular expression that finds the content of the day badge in your file. -# starsRegex: '(?<=https:\/\/img\.shields\.io\/badge\/stars%20⭐-)[0-9]+(?=-yellow)' # Regular expression that finds the content of the stars badge in your file. -# daysCompletedRegex: '(?<=https:\/\/img\.shields\.io\/badge\/days%20completed-)[0-9]+(?=-red)' # Regular expression that finds the content of the days completed badge iun your file. - - - uses: stefanzweifel/git-auto-commit-action@v4 # Step that pushes these local changes back to your github repo - with: - commit_message: Update badges - file_pattern: README.md diff --git a/.gitignore b/.gitignore index 7cea34d..ab90197 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*/input -*/test-input \ No newline at end of file +# per https://twitter.com/ericwastl/status/1465805354214830081 +*/input \ No newline at end of file diff --git a/01/01.py b/01/01.py new file mode 100644 index 0000000..cb0c45c --- /dev/null +++ b/01/01.py @@ -0,0 +1,21 @@ +with open('input', 'r') as fp: + file = fp.read() + +elves_calories = file.split('\n\n') +elves = [] +for calories_string in elves_calories: + calories_list = calories_string.split('\n') + calories = 0 + while calories_list: + calories += int(calories_list[-1]) + calories_list.pop() + elves.append(calories) +print(elves) +print(max(elves)) + +top_3 = [] +while len(top_3) < 3: + biggest = max(elves) + top_3.append(biggest) + elves.remove(biggest) +print(top_3) diff --git a/01/01a.py b/01/01a.py deleted file mode 100644 index 2e5a7eb..0000000 --- a/01/01a.py +++ /dev/null @@ -1,18 +0,0 @@ -with open('input', 'r') as f: - lines = f.readlines() - -left, right = [], [] - -for line in lines: - l, r = line.split() - left.append(int(l)) - right.append(int(r)) - -left.sort() -right.sort() - -if len(left) != len(right): print('fail') -else: - diff = 0 - for i in range(len(left)): diff += abs(left[i] - right[i]) - print(diff) \ No newline at end of file diff --git a/01/01b.py b/01/01b.py deleted file mode 100644 index 6178dbc..0000000 --- a/01/01b.py +++ /dev/null @@ -1,23 +0,0 @@ -with open('input', 'r') as f: - lines = f.readlines() - -left, right = [], [] - -for line in lines: - l, r = line.split() - left.append(int(l)) - right.append(int(r)) - -right2 = {} -for r_item in right: - if r_item in right2.keys(): right2[r_item] += 1 - else: right2[r_item] = 1 - -print(right2) - -similarity = 0 -for l_item in left: - if l_item in right2.keys(): - similarity += (l_item * right2[l_item]) - -print(similarity) \ No newline at end of file diff --git a/02/02-a.py b/02/02-a.py new file mode 100644 index 0000000..e8fdf65 --- /dev/null +++ b/02/02-a.py @@ -0,0 +1,26 @@ +with open('input', 'r') as fp: + file = fp.readlines() + pairs = [] + for line in file: + line = line.strip() + pairs.append(line.split(' ')) + +# A/X = rock (1) +# B/Y = paper (2) +# C/Z = scissors (3) + +# win = 6, draw = 3, lose = 0 + +player_wins = [['A', 'Y'], ['B', 'Z'], ['C', 'X']] +player_draw = [['A', 'X'], ['B', 'Y'], ['C', 'Z']] +player_loss = [['A', 'Z'], ['B', 'X'], ['C', 'Y']] +player_points = {'X': 1, 'Y': 2, 'Z': 3} + +points = 0 +for pair in pairs: + if pair in player_wins: + points += 6 + elif pair in player_draw: + points += 3 + points += player_points[pair[1]] +print(points) diff --git a/02/02-b.py b/02/02-b.py new file mode 100644 index 0000000..ae91920 --- /dev/null +++ b/02/02-b.py @@ -0,0 +1,30 @@ +with open('input', 'r') as fp: + file = fp.readlines() + pairs = [] + for line in file: + line = line.strip() + pairs.append(line.split(' ')) + +# A = rock (1) +# B = paper (2) +# C = scissors (3) + +# Z win = 6, Y draw = 3, X lose = 0 + +win_vs = {'A': 'B', 'B': 'C', 'C': 'A'} +drw_vs = {'A': 'A', 'B': 'B', 'C': 'C'} +lse_vs = {'A': 'C', 'B': 'A', 'C': 'B'} +points = {'A': 1, 'B': 2, 'C': 3} + +total = 0 +for pair in pairs: + if pair[1] == 'Z': + total += 6 + total += points[win_vs[pair[0]]] + elif pair[1] == 'Y': + total += 3 + total += points[drw_vs[pair[0]]] + elif pair[1] == 'X': + total += 0 + total += points[lse_vs[pair[0]]] +print(total) diff --git a/02/02a.py b/02/02a.py deleted file mode 100644 index 1efdc25..0000000 --- a/02/02a.py +++ /dev/null @@ -1,45 +0,0 @@ -def is_safe(increasing, n1, n2): - if increasing: - return n2 in range(n1+1, n1+4) - else: - return n2 in range(n1-3, n1) - - -with open('input', 'r') as f: - reports = f.read().splitlines() - -print(reports) - -report_report = {'safe': 0, 'unsafe': 0} - -for report in reports: - report = report.split() - report = [ int(x) for x in report ] - copied = list(report) - copied.sort() - if report == copied: - going = True - elif report == copied[::-1]: - going = False - else: - report_report['unsafe'] += 1 - continue - - - while len(report) != 1: - if is_safe(going, report[0], report[1]): - report.pop(0) - continue - else: - break - - if len(report) == 1: - report_report['safe'] += 1 - continue - else: - report_report['unsafe'] += 1 - continue - - - -print(report_report) diff --git a/02/02b.py b/02/02b.py deleted file mode 100644 index e65b8e9..0000000 --- a/02/02b.py +++ /dev/null @@ -1,54 +0,0 @@ -def is_safe(increasing, n1, n2): - if increasing: - return n2 in range(n1+1, n1+4) - else: - return n2 in range(n1-3, n1) - - -with open('input', 'r') as f: - reports = f.read().splitlines() - -print(reports) - -report_report = {'safe': 0, 'unsafe': 0} - -for original_report in reports: - this_report = False - original_report = [ int(x) for x in original_report.split() ] - - for i in range(len(original_report)): - report = list(original_report) - report.pop(i) - - - copied = list(report) - copied.sort() - if report == copied: - going = True - elif report == copied[::-1]: - going = False - else: - continue - - - while len(report) != 1: - if is_safe(going, report[0], report[1]): - report.pop(0) - continue - else: - break - - if len(report) == 1: - this_report = True - continue - else: - continue - - if this_report: - report_report['safe'] += 1 - else: - report_report['unsafe'] += 1 - - - -print(report_report) diff --git a/02/README.md b/02/README.md deleted file mode 100644 index 3c64a1c..0000000 --- a/02/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Day 2! - -Not particularly proud of this one but ended up just brute forcing as I was trying to add the failed level back in but realised that was the wrong way to do it soooo late - then just progressively started moving stuff in to the for loop til it worked. Eek \ No newline at end of file diff --git a/03/03-a.py b/03/03-a.py new file mode 100644 index 0000000..5dc0b53 --- /dev/null +++ b/03/03-a.py @@ -0,0 +1,29 @@ +import string + + +lower = list(string.ascii_lowercase) +upper = list(string.ascii_uppercase) + + +def get_prio(letter): + if letter in lower: + return lower.index(letter) + 1 + else: + return upper.index(letter) + 27 + + +with open('input', 'r') as fp: + rucksacks = fp.readlines() + +priorities = 0 +for rucksack in rucksacks: + rucksack = rucksack.strip() + slicer = len(rucksack)//2 + comp_one, comp_two = rucksack[:slicer], rucksack[slicer:] + for letter in comp_one: + print(letter) + if letter in comp_two: + print('found letter', letter, comp_one, comp_two) + priorities += get_prio(letter) + break +print(priorities) diff --git a/03/03-b.py b/03/03-b.py new file mode 100644 index 0000000..0a84a03 --- /dev/null +++ b/03/03-b.py @@ -0,0 +1,28 @@ +import string + + +lower = list(string.ascii_lowercase) +upper = list(string.ascii_uppercase) + + +def get_prio(letter): + if letter in lower: + return lower.index(letter) + 1 + else: + return upper.index(letter) + 27 + + +with open('input', 'r') as fp: + rucksacks = fp.readlines() + +priorities = 0 +for i in range(len(rucksacks)//3): + group = rucksacks[3*i:3*i+3] + for j in range(3): + group[j] = group[j].strip() + for letter in group[0]: + if letter in group[1] and letter in group[2]: + print('badge found', letter, group) + priorities += get_prio(letter) + break +print(priorities) diff --git a/03/03a.py b/03/03a.py deleted file mode 100644 index 8e3e089..0000000 --- a/03/03a.py +++ /dev/null @@ -1,13 +0,0 @@ -import re - -with open('input', 'r') as f: instructions = f.read() - -results = re.findall(r"mul\([0-9]{1,3},[0-9]{1,3}\)", instructions) - -total = 0 -for result in results: - a, b = result.replace("mul(","").replace(")","").split(",") - print(f"{result=} {a=} {b=} {int(a) * int(b)=}") - total += int(a) * int(b) - -print(total) \ No newline at end of file diff --git a/03/03b.py b/03/03b.py deleted file mode 100644 index 17c2715..0000000 --- a/03/03b.py +++ /dev/null @@ -1,40 +0,0 @@ -import re - -with open('input', 'r') as f: instructions = f.read() - -total = 0 - -do = True -print(instructions) -while instructions: - #print(total) - if do: - # First check there's not a dont() coming up - print(instructions[:7]) - if instructions[:7] == "don't()": - do = False - continue - # Then check if there's a valid mul(xxx,yyy) coming up - else: - match = re.search(r"mul\([0-9]{1,3},[0-9]{1,3}\)", instructions[:12]) - if match: - #print(match.group()) - a, b = match.group().replace("mul(","").replace(")","").split(",") - total += int(a) * int(b) - #print(match.span()) - instructions = instructions[match.span()[1]:] - continue - else: - instructions = instructions[1:] - continue - - else: - # Check if there's a do() coming up - print(instructions[:4]) - if instructions[:4] == "do()": - do = True - continue - else: - instructions = instructions[1:] - -print(total) \ No newline at end of file diff --git a/04/04-a.py b/04/04-a.py new file mode 100644 index 0000000..189e476 --- /dev/null +++ b/04/04-a.py @@ -0,0 +1,21 @@ +with open('input', 'r') as fp: + lines = [line.strip() for line in fp.readlines()] + +contained = 0 +for line in lines: + a, b = line.split(',') + + # otherwise compares them as strings :/ + a_low, a_high = [int(i) for i in a.split('-')] + b_low, b_high = [int(i) for i in b.split('-')] + + if b_low <= a_low and a_high <= b_high: + print(line, 'a inside b', a_low, a_high, b_low, b_high) + contained += 1 + elif a_low <= b_low and b_high <= a_high: + print(line, 'b inside a', a_low, a_high, b_low, b_high) + contained += 1 + else: + print(line, 'not fully contained') + +print(contained) diff --git a/04/04-b.py b/04/04-b.py new file mode 100644 index 0000000..39922e8 --- /dev/null +++ b/04/04-b.py @@ -0,0 +1,18 @@ +with open('input', 'r') as fp: + lines = [line.strip() for line in fp.readlines()] + +overlap = 0 +for line in lines: + a_line, b_line = line.split(',') + + # otherwise compares them as strings :/ + a_low, a_high = [int(i) for i in a_line.split('-')] + b_low, b_high = [int(i) for i in b_line.split('-')] + + a = range(a_low, a_high+1) + b = range(b_low, b_high+1) + intersection = list(set(a) & set(b)) + if intersection: + overlap += 1 + +print(overlap) diff --git a/04/04a.py b/04/04a.py deleted file mode 100644 index 770d809..0000000 --- a/04/04a.py +++ /dev/null @@ -1,51 +0,0 @@ -import numpy as np -import re - -with open('input', 'r') as f: source = f.read().split('\n') - -matrix = [] - -for y in source: - row = [] - for x in range(len(y)): - row.append(y[x]) - matrix.append(row) - -print(matrix) - -npm = np.matrix(matrix) -print(npm) - -# No way I could've done this without numpy and this answer: https://stackoverflow.com/a/6313414 -npdiags = [npm[::-1,:].diagonal(i) for i in range(-npm.shape[0]+1,npm.shape[1])] -npdiags.extend(npm.diagonal(i) for i in range(npm.shape[1]-1,-npm.shape[0],-1)) -diags = [ i.tolist() for i in npdiags ] - -print(diags) - -total = 0 - -# Search rows -for y in matrix: - row = ''.join(y) - # This total adding thing shoulda been a function - total += len(re.findall(r'XMAS', row)) - total += len(re.findall(r'XMAS', row[::-1])) - -print(f'{total=}') - -# Search columns -for x in range(len(matrix[0])): - column = ''.join(npm[:, x].flatten().tolist()[0]) - total += len(re.findall(r'XMAS', column)) - total += len(re.findall(r'XMAS', column[::-1])) - -print(f'{total=}') - -# Search diagonals -for d in diags: - diag = ''.join(d[0]) - total += len(re.findall(r'XMAS', diag)) - total += len(re.findall(r'XMAS', diag[::-1])) - -print(f'{total=}') \ No newline at end of file diff --git a/04/04b.py b/04/04b.py deleted file mode 100644 index d71f235..0000000 --- a/04/04b.py +++ /dev/null @@ -1,31 +0,0 @@ -with open('input', 'r') as f: source = f.read().split('\n') - -matrix = [] - -for y in source: - row = [] - for x in range(len(y)): - row.append(y[x]) - matrix.append(row) - -print(matrix) - -count = 0 - -# M A S is 3 long so -for y in range(len(matrix) - 2): - for x in range(len(matrix[x]) - 2): - print(f'{x},{y} = {matrix[y][x]}') - - tl = matrix[y][x] - tr = matrix[y][x+2] - mi = matrix[y+1][x+1] - bl = matrix[y+2][x] - br = matrix[y+2][x+2] - - if (tl == "M" and br == "S") or (tl == "S" and br == "M"): - if (tr == "S" and bl == "M") or (tr == "M" and bl == "S"): - if (mi == "A"): - count += 1 - -print(f'{count=}') \ No newline at end of file diff --git a/05/05-a.py b/05/05-a.py new file mode 100644 index 0000000..aecd276 --- /dev/null +++ b/05/05-a.py @@ -0,0 +1,27 @@ +with open('input', 'r') as fp: + file = fp.readlines() + +pivot = file.index('\n') +grid, instructions = [i.rstrip() for i in file[:pivot]], [i.rstrip() for i in file[pivot+1:]] + +columns = [1,5,9,13,17,21,25,29,33] +piles = [[], [], [], [], [], [], [], [], []] + +height = len(grid) - 1 +for y in range(2, height + 2): + for x in range(9): + if grid[-y][columns[x]] != ' ': + piles[x].append(grid[-y][columns[x]]) +print(piles) + +for inst in instructions: + _, num, _, from_pile, _, to_pile = [int(i) if i.isnumeric() else "" for i in inst.split(' ')] + + for j in range(num): + popped = piles[from_pile-1].pop() + print('popped', popped, 'from', from_pile) + piles[to_pile-1].append(popped) + +print(piles) +for k in piles: + print(k[-1]) diff --git a/05/05-b.py b/05/05-b.py new file mode 100644 index 0000000..9e76bf5 --- /dev/null +++ b/05/05-b.py @@ -0,0 +1,30 @@ +#editing this file to fix the annoying commit message I wrote + +with open('input-main', 'r') as fp: + file = fp.readlines() + +pivot = file.index('\n') +grid, instructions = [i.rstrip() for i in file[:pivot]], [i.rstrip() for i in file[pivot+1:]] + +columns = [1,5,9,13,17,21,25,29,33] +piles = [[], [], [], [], [], [], [], [], []] + +height = len(grid) - 1 +for y in range(2, height + 2): + for x in range(9): + if grid[-y][columns[x]] != ' ': + piles[x].append(grid[-y][columns[x]]) +print(piles) + +for inst in instructions: + _, num, _, from_pile, _, to_pile = [int(i) if i.isnumeric() else "" for i in inst.split(' ')] + + popped, piles[from_pile-1] = piles[from_pile-1][-num:][::-1], piles[from_pile-1][:-num] + print(inst, 'popped', popped, f"({num})", 'from', from_pile) + while popped: + crate = popped.pop() + piles[to_pile-1].append(crate) + +print(piles) +for k in piles: + print(k[-1]) diff --git a/06/06.py b/06/06.py new file mode 100644 index 0000000..6c3d279 --- /dev/null +++ b/06/06.py @@ -0,0 +1,15 @@ +import sys +with open('input', 'r') as fp: + file = fp.read().strip() + +# part a +msg_length = 4 +#  part b +#msg_length = 14 + +for i in range(len(file)): + chars = list(file[i:i+msg_length]) + print(chars) + if len(set(chars)) == msg_length: + print(i+msg_length) + sys.exit() diff --git a/07/07a.py b/07/07a.py new file mode 100644 index 0000000..b737270 --- /dev/null +++ b/07/07a.py @@ -0,0 +1,86 @@ +big_size = 0 + +class Directory: + def __init__(self, parent = None): + self.files = {} + self.subdirs = {} + self.parent = parent + + def get_size(self): + global big_size + size = 0 + for file in self.files: + #print(size, self.files, file) + file_size = self.files[file] + print("*", file, file_size) + size += file_size + for dir in self.subdirs: + #print(size, self.subdirs, dir) + subdir_size = self.subdirs[dir].get_size() + print("#", dir, subdir_size) + with open('subdirs', 'a+') as fp: + fp.write("# " + dir + " " + str(subdir_size) + '\n') + size += subdir_size + if subdir_size <= 100000: + big_size += subdir_size + return size + + def add_dir(self, name): + self.subdirs[name] = Directory(self) + return self.subdirs[name] + + def add_file(self, name, size): + self.files[name] = size + + def dir_exists(self, name): + return name in self.subdirs + + def list_dirs(self): + print(self.subdirs) + + def get_dirs(self): + return self.subdirs + + def list_files(self): + print(self.files) + + def get_files(self): + return self.files + + def get_parent(self): + if self.parent == None: return self + return self.parent + +with open('input', 'r') as fp: + history = fp.readlines()[::-1] + +cwd = Directory() +root = cwd.get_parent() + +while history: + line = history.pop().strip() + + if line.startswith('$'): # command + line = line[2:] + if line == 'ls': + files_to_add = [] + while history and not history[-1].startswith('$'): files_to_add.append(history.pop().strip()) + #print(files_to_add) + for file in files_to_add: + if file.startswith('dir'): + cwd.add_dir(file.split(' ')[1]) + else: + size, name = file.split(' ') + cwd.add_file(name, int(size)) + elif line.startswith('cd'): + command, operand = line.split(' ') + #print(command, operand) + if operand == '/': cwd = root + elif operand == '..': cwd = cwd.get_parent() + elif cwd.dir_exists(operand): cwd = cwd.get_dirs()[operand] + else: cwd = cwd.add_dir(operand) + else: + print('something is very wrong') + +print(root.get_size()) +print(big_size) diff --git a/07/07b.py b/07/07b.py new file mode 100644 index 0000000..1096691 --- /dev/null +++ b/07/07b.py @@ -0,0 +1,23 @@ +# used 42143088 +# total 70000000 +# need 30000000 +# delta 27856912 + +# delete 2143088 + +# subdirs is a file created from 07-a.py + +with open('subdirs', 'r') as fp: + file = [i.strip() for i in fp.readlines()] + +subdirs = {} +for dir in file: + _, name, size = dir.split(' ') + subdirs[name] = int(size) + +sorted_subdirs = sorted(subdirs.items(), key=lambda x: x[1]) + +for subdir in sorted_subdirs: + print(subdir[0], subdir[1]) + if subdir[1] > 2143088: + print("!!", subdir[0], subdir[1]) diff --git a/07/subdirs b/07/subdirs new file mode 100644 index 0000000..66342b3 --- /dev/null +++ b/07/subdirs @@ -0,0 +1,393 @@ +# tcdmgwp 277338 +# dngldfww 102218 +# dzplphqw 263191 +# mvslzl 365409 +# nnlzrwgh 141976 +# svc 281339 +# wshf 25072 +# dhbrmn 652883 +# wvfdjv 104669 +# rcdwft 104669 +# wtmdzgvg 1099415 +# qdtls 1815835 +# brhvclj 340451 +# brhvclj 340451 +# clnvqg 772195 +# svc 202934 +# pqp 409771 +# tdvtcmwz 100584 +# qbms 456639 +# wshwhzw 116856 +# dfmgqmvm 775231 +# ttntt 901742 +# rlbnv 55214 +# wfcczs 55214 +# wshwhzw 34867 +# tfns 2267101 +# brhvclj 4647484 +# sgbwd 267083 +# ttntt 243283 +# bchstbpm 510366 +# dpnqrg 140379 +# gsvwsc 84951 +# rfcssr 13174 +# ttntt 162959 +# cpbh 13930 +# brhvclj 394189 +# drgcn 641306 +# ttntt 43248 +# svc 313759 +# mrv 1374480 +# vhjtgv 98550 +# zgtnfm 98550 +# wshwhzw 1681268 +# jshpz 2806903 +# bgbdbr 2806903 +# qqr 143274 +# brhvclj 67021 +# gsplfsvm 103196 +# zzhwq 103196 +# clnvqg 170217 +# qwwl 411742 +# brhvclj 820693 +# cjcpzv 173344 +# gcnc 1525047 +# clnvqg 1667013 +# bddbffsf 181609 +# wshwhzw 80221 +# bpgmc 122736 +# brhvclj 74083 +# nrrpsn 58623 +# ttntt 186640 +# brhvclj 442082 +# brhvclj 997867 +# flz 249582 +# ddrthl 333778 +# pmgzdp 94671 +# qgvzbclg 183904 +# nhjthr 383644 +# dptjfd 663986 +# hqncdcdh 218709 +# svc 1216473 +# ddbcvhqr 2195372 +# gsfzgvpz 266749 +# dlmhm 50087 +# mpmtj 254330 +# ljwrdb 304417 +# rlj 846508 +# svc 345941 +# pqvlqpdt 211827 +# hrzsfhct 351358 +# snhftjr 198904 +# hdlcnfm 198904 +# vjjgrt 725091 +# wshwhzw 1529878 +# brhvclj 123699 +# zhczqq 123699 +# bmgbjnbr 6761944 +# dvqszvl 172068 +# wshwhzw 57060 +# clnvqg 760847 +# rzsqqhn 1262514 +# ttr 1262514 +# brhvclj 1434582 +# clnqz 333622 +# ttntt 224617 +# gdftglf 480432 +# ggrwpjjg 813709 +# nrd 205734 +# ffqg 205734 +# brhvclj 75177 +# svc 424171 +# vgqf 906981 +# ctlddnj 1665526 +# czjnvnn 181131 +# gpwpc 257389 +# lrgtg 257389 +# ttntt 40453 +# brhvclj 40453 +# hnqqrdf 40453 +# pfhrgj 41975 +# ttntt 535492 +# vzhpqb 889704 +# tthrf 1814138 +# ddwg 2042410 +# mjvm 4267863 +# svc 110021 +# bscqn 25049 +# ttntt 157797 +# njsnwmrc 534556 +# dmnmcgr 152719 +# ffqfqvjv 102537 +# svc 596114 +# pwrjt 698651 +# nnhcsb 1432335 +# wshwhzw 2655317 +# ddzjr 3030705 +# dhhwdbb 201253 +# ztlvdwq 489732 +# brhvclj 670892 +# ttntt 991086 +# clnvqg 371906 +# wshwhzw 51089 +# gwcsprqv 547929 +# gqhqmlhm 211887 +# mbfftpbj 60539 +# nvjj 272426 +# fvdch 124864 +# tqr 124864 +# clnvqg 397290 +# spffhcnz 865972 +# svc 143992 +# jrzmrg 143992 +# wshwhzw 374880 +# wshwhzw 2815322 +# fnmhc 4007661 +# tbhwr 42758 +# vbtmfp 171021 +# brhvclj 388576 +# jrww 110574 +# sqtzndzg 450791 +# zrzrjm 1413797 +# zmchn 8854759 +# svc 14744011 +# jlsvjcdm 23681395 +# brhvclj 254250 +# fvqh 18471 +# tczvhsgn 241619 +# zbbq 82844 +# jptq 889763 +# nbjljt 214471 +# brhvclj 60019 +# ldrsbj 143346 +# rszwnh 758491 +# sctfsvs 1029099 +# rpgm 205836 +# svc 205836 +# swsjjr 348149 +# tstct 204812 +# mzmqr 2980133 +# clnvqg 121970 +# ldcwjlm 709232 +# rtmg 1284419 +# ttntt 120262 +# wgwvd 346057 +# gltsgnf 466319 +# sgqvlr 364738 +# psltbtl 760701 +# tqnmwdl 1542529 +# clnvqg 34772236 +# dtqtvvrn 511536 +# csqfmjz 124616 +# nsq 361294 +# dvslq 495261 +# fbzss 153744 +# ttntt 109641 +# nfgnnt 758646 +# rwzmjgqz 12039 +# wshwhzw 57458 +# dlr 142748 +# nzq 242998 +# wtvtszw 536940 +# lcz 1489699 +# pcqjncwl 10646 +# qwvfpgl 327513 +# rtmj 79449 +# shg 27187 +# tcdmgwp 277338 +# dngldfww 102218 +# dzplphqw 263191 +# mvslzl 365409 +# nnlzrwgh 141976 +# svc 281339 +# wshf 25072 +# dhbrmn 652883 +# wvfdjv 104669 +# rcdwft 104669 +# wtmdzgvg 1099415 +# qdtls 1815835 +# brhvclj 340451 +# brhvclj 340451 +# clnvqg 772195 +# svc 202934 +# pqp 409771 +# tdvtcmwz 100584 +# qbms 456639 +# wshwhzw 116856 +# dfmgqmvm 775231 +# ttntt 901742 +# rlbnv 55214 +# wfcczs 55214 +# wshwhzw 34867 +# tfns 2267101 +# brhvclj 4647484 +# sgbwd 267083 +# ttntt 243283 +# bchstbpm 510366 +# dpnqrg 140379 +# gsvwsc 84951 +# rfcssr 13174 +# ttntt 162959 +# cpbh 13930 +# brhvclj 394189 +# drgcn 641306 +# ttntt 43248 +# svc 313759 +# mrv 1374480 +# vhjtgv 98550 +# zgtnfm 98550 +# wshwhzw 1681268 +# jshpz 2806903 +# bgbdbr 2806903 +# qqr 143274 +# brhvclj 67021 +# gsplfsvm 103196 +# zzhwq 103196 +# clnvqg 170217 +# qwwl 411742 +# brhvclj 820693 +# cjcpzv 173344 +# gcnc 1525047 +# clnvqg 1667013 +# bddbffsf 181609 +# wshwhzw 80221 +# bpgmc 122736 +# brhvclj 74083 +# nrrpsn 58623 +# ttntt 186640 +# brhvclj 442082 +# brhvclj 997867 +# flz 249582 +# ddrthl 333778 +# pmgzdp 94671 +# qgvzbclg 183904 +# nhjthr 383644 +# dptjfd 663986 +# hqncdcdh 218709 +# svc 1216473 +# ddbcvhqr 2195372 +# gsfzgvpz 266749 +# dlmhm 50087 +# mpmtj 254330 +# ljwrdb 304417 +# rlj 846508 +# svc 345941 +# pqvlqpdt 211827 +# hrzsfhct 351358 +# snhftjr 198904 +# hdlcnfm 198904 +# vjjgrt 725091 +# wshwhzw 1529878 +# brhvclj 123699 +# zhczqq 123699 +# bmgbjnbr 6761944 +# dvqszvl 172068 +# wshwhzw 57060 +# clnvqg 760847 +# rzsqqhn 1262514 +# ttr 1262514 +# brhvclj 1434582 +# clnqz 333622 +# ttntt 224617 +# gdftglf 480432 +# ggrwpjjg 813709 +# nrd 205734 +# ffqg 205734 +# brhvclj 75177 +# svc 424171 +# vgqf 906981 +# ctlddnj 1665526 +# czjnvnn 181131 +# gpwpc 257389 +# lrgtg 257389 +# ttntt 40453 +# brhvclj 40453 +# hnqqrdf 40453 +# pfhrgj 41975 +# ttntt 535492 +# vzhpqb 889704 +# tthrf 1814138 +# ddwg 2042410 +# mjvm 4267863 +# svc 110021 +# bscqn 25049 +# ttntt 157797 +# njsnwmrc 534556 +# dmnmcgr 152719 +# ffqfqvjv 102537 +# svc 596114 +# pwrjt 698651 +# nnhcsb 1432335 +# wshwhzw 2655317 +# ddzjr 3030705 +# dhhwdbb 201253 +# ztlvdwq 489732 +# brhvclj 670892 +# ttntt 991086 +# clnvqg 371906 +# wshwhzw 51089 +# gwcsprqv 547929 +# gqhqmlhm 211887 +# mbfftpbj 60539 +# nvjj 272426 +# fvdch 124864 +# tqr 124864 +# clnvqg 397290 +# spffhcnz 865972 +# svc 143992 +# jrzmrg 143992 +# wshwhzw 374880 +# wshwhzw 2815322 +# fnmhc 4007661 +# tbhwr 42758 +# vbtmfp 171021 +# brhvclj 388576 +# jrww 110574 +# sqtzndzg 450791 +# zrzrjm 1413797 +# zmchn 8854759 +# svc 14744011 +# jlsvjcdm 23681395 +# brhvclj 254250 +# fvqh 18471 +# tczvhsgn 241619 +# zbbq 82844 +# jptq 889763 +# nbjljt 214471 +# brhvclj 60019 +# ldrsbj 143346 +# rszwnh 758491 +# sctfsvs 1029099 +# rpgm 205836 +# svc 205836 +# swsjjr 348149 +# tstct 204812 +# mzmqr 2980133 +# clnvqg 121970 +# ldcwjlm 709232 +# rtmg 1284419 +# ttntt 120262 +# wgwvd 346057 +# gltsgnf 466319 +# sgqvlr 364738 +# psltbtl 760701 +# tqnmwdl 1542529 +# clnvqg 34772236 +# dtqtvvrn 511536 +# csqfmjz 124616 +# nsq 361294 +# dvslq 495261 +# fbzss 153744 +# ttntt 109641 +# nfgnnt 758646 +# rwzmjgqz 12039 +# wshwhzw 57458 +# dlr 142748 +# nzq 242998 +# wtvtszw 536940 +# lcz 1489699 +# pcqjncwl 10646 +# qwvfpgl 327513 +# rtmj 79449 +# shg 27187 +# tcdmgwp 277338 diff --git a/08/08-a.py b/08/08-a.py new file mode 100644 index 0000000..7003f8a --- /dev/null +++ b/08/08-a.py @@ -0,0 +1,45 @@ +with open('input', 'r') as fp: + grid = [i.strip() for i in fp.readlines()] + +visible = 0 +for y in range(len(grid)): + for x in range(len(grid[y])): + + left, right, top, bottom = True, True, True, True + + # check left, y remains same + for xr in range(0, x): + if xr == x and y == y: + continue + if grid[y][xr] >= grid[y][x]: + left = False + + # check top, x remains same + for yr in range(0, y): + if yr == y and x == x: + continue + if grid[yr][x] >= grid[y][x]: + top = False + + # check right, y remains same + for xr in range(x, len(grid[y])): + if xr == x and y == y: + continue + if grid[y][xr] >= grid[y][x]: + right = False + + # check bottom, x remains same + for yr in range(y, len(grid)): + if yr == y and x == x: + continue + if grid[yr][x] >= grid[y][x]: + bottom = False + + vis = left or right or top or bottom + if vis: + visible += 1 + + print( + f"({y+1},{x+1}) = {grid[y][x]} | {vis=} | {left=} {right=} {top=} {bottom=}") + +print(visible) diff --git a/08/08-b.py b/08/08-b.py new file mode 100644 index 0000000..2c2d89b --- /dev/null +++ b/08/08-b.py @@ -0,0 +1,67 @@ +with open('input', 'r') as fp: + grid = [i.strip() for i in fp.readlines()] + +scenics = [] + +visible = 0 +for y in range(len(grid)): + for x in range(len(grid[y])): + + left, right, top, bottom = True, True, True, True + l_sc, r_sc, t_sc, b_sc = 0, 0, 0, 0 + + # check left, y remains same + for xr in range(0, x)[::-1]: + if xr == x and y == y: + continue + if grid[y][xr] >= grid[y][x]: + left = False + l_sc += 1 + break + else: + l_sc += 1 + + # check top, x remains same + for yr in range(0, y)[::-1]: + if yr == y and x == x: + continue + if grid[yr][x] >= grid[y][x]: + top = False + t_sc += 1 + break + else: + t_sc += 1 + + # check right, y remains same + for xr in range(x, len(grid[y])): + if xr == x and y == y: + continue + if grid[y][xr] >= grid[y][x]: + right = False + r_sc += 1 + break + else: + r_sc += 1 + + # check bottom, x remains same + for yr in range(y, len(grid)): + if yr == y and x == x: + continue + if grid[yr][x] >= grid[y][x]: + bottom = False + b_sc += 1 + break + else: + b_sc += 1 + + vis = left or right or top or bottom + if vis: + visible += 1 + scenic = l_sc * r_sc * t_sc * b_sc + scenics.append(scenic) + + print( + f"({y+1},{x+1}) = {grid[y][x]} | {vis=} | {scenic=} | {l_sc=} {r_sc=} {t_sc=} {b_sc=}") + +print(visible) +print(max(scenics)) diff --git a/README.md b/README.md deleted file mode 100644 index bfa69ad..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -![](https://img.shields.io/badge/day%20📅-25-blue) -![](https://img.shields.io/badge/days%20completed-4-red) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c9e0e32 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +# 2022