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..3f7ac73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*/input -*/test-input \ No newline at end of file +*/inpu* +.DS_Store \ No newline at end of file diff --git a/01/01-a.py b/01/01-a.py new file mode 100644 index 0000000..69cdb0e --- /dev/null +++ b/01/01-a.py @@ -0,0 +1,19 @@ +import re + +with open("input3", "r") as f: + lines = f.readlines() + +total = 0 + +for line in lines: + line = line.strip() + # print(line) + split = re.split(r"[a-zA-Z]+", line) + # print(split) + rejoin = "".join(split) + # print(rejoin) + calibration = rejoin[0] + rejoin[-1] + # print(calibration) + total += int(calibration) + +print(total) diff --git a/01/01-b.py b/01/01-b.py new file mode 100644 index 0000000..4a36f6f --- /dev/null +++ b/01/01-b.py @@ -0,0 +1,29 @@ +with open("input", "r") as f: + lines = f.readlines() + +new_input = [] +replacements = { + "one": "1", + "two": "2", + "three": "3", + "four": "4", + "five": "5", + "six": "6", + "seven": "7", + "eight": "8", + "nine": "9", +} + +for line in lines: + line = line.strip() + new_line = "" + for letter in line: + new_line += letter + for replacement in replacements.keys(): + if new_line.endswith(replacement): + new_line = new_line.replace(replacement, replacements[replacement]) + print(f'"{line}" -> "{new_line}"') + new_input.append(new_line) + +with open("input2", "w+") as f: + f.write("\n".join(new_input)) diff --git a/01/01-c.py b/01/01-c.py new file mode 100644 index 0000000..a3ad973 --- /dev/null +++ b/01/01-c.py @@ -0,0 +1,38 @@ +with open("input", "r") as f: + lines = f.readlines() + +all_numbers = [] +replacements = { + "one": "1", + "two": "2", + "three": "3", + "four": "4", + "five": "5", + "six": "6", + "seven": "7", + "eight": "8", + "nine": "9", +} + +for line in lines: + line = line.strip() + print(line) + new_line = "" + this_line = [] + for letter in line: + new_line += letter + if letter.isdigit(): + print(f"{letter} is a digit") + this_line.append(letter) + else: + for replacement in replacements: + if new_line.endswith(replacement): + print(f"{new_line} ends with {replacement}") + this_line.append(replacements[replacement]) + all_numbers.append(this_line) + +print(all_numbers) + +with open("input3", "w+") as f: + for line in all_numbers: + f.write("".join(line) + "\n") 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..ad79341 --- /dev/null +++ b/02/02-a.py @@ -0,0 +1,26 @@ +with open("input", "r") as f: + lines = f.readlines() + +# The Elf would first like to know which games would have been possible +# if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes? + +limits = {"red": 12, "green": 13, "blue": 14} +games = list(range(1, len(lines) + 1)) + +for line in lines: + line = line.strip() + game_id = int(line.split(":")[0].split(" ")[-1]) + print(game_id) + rounds = line.split(":")[1].split(";") + for this_round in rounds: + for each_colour in this_round.split(","): + num = int(each_colour.strip().split(" ")[0]) + colour = each_colour.strip().split(" ")[1] + if num > limits[colour]: + try: + games.remove(game_id) + except: + print("already removed") + +print(games) +print(sum(games)) diff --git a/02/02-b.py b/02/02-b.py new file mode 100644 index 0000000..7c441fd --- /dev/null +++ b/02/02-b.py @@ -0,0 +1,22 @@ +with open("input", "r") as f: + lines = f.readlines() + +# The Elf would first like to know which games would have been possible +# if the bag contained only 12 red cubes, 13 green cubes, and 14 blue cubes? + +powers = [] + +for line in lines: + line = line.strip() + game_id = int(line.split(":")[0].split(" ")[-1]) + minimums = {"red": 0, "green": 0, "blue": 0} + rounds = line.split(":")[1].split(";") + for this_round in rounds: + for each_colour in this_round.split(","): + num = int(each_colour.strip().split(" ")[0]) + colour = each_colour.strip().split(" ")[1] + if num > minimums[colour]: + minimums[colour] = num + powers.append(minimums["red"] * minimums["green"] * minimums["blue"]) + +print(sum(powers)) 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/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/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/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)