Skip to content

Commit

Permalink
2023 day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted Cassirer committed Dec 1, 2023
1 parent f971ffe commit 36a3600
Show file tree
Hide file tree
Showing 244 changed files with 1,558 additions and 141 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
run: poetry install
- name: Black code style check
run: |
black --check -l 120 .
poetry run black --check -l 120 .
- name: Test with pytest
run: |
pytest
poetry run pytest
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.vscode
__pycache__/
venv/
*.egg-info/
*.pyc
*.pyc
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
File renamed without changes.
7 changes: 7 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions aoc_cas/__init__.py

This file was deleted.

32 changes: 0 additions & 32 deletions aoc_cas/cli.py

This file was deleted.

1,322 changes: 1,322 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tool.poetry]
name = "advent-of-code"
version = "0.1.0"
description = ""
authors = ["Ted Cassirer <[email protected]>"]
readme = "README.md"

packages = [
{include = "aoc2015", from = "src/"},
{include = "aoc2016", from = "src/"},
{include = "aoc2019", from = "src/"},
{include = "aoc2020", from = "src/"},
{include = "aoc2021", from = "src/"},
{include = "aoc2022", from = "src/"},
{include = "scripts", from = "src/"},
]



[tool.poetry.dependencies]
python = "^3.11"
advent-of-code-data = "^2.0.1"
black = "^23.11.0"
numpy = "^1.26.2"
pytest = "^7.4.3"
poetry = "^1.7.1"
click = "^8.1.7"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
#
#[tool.poetry.scripts]
#aoccas = "scripts.cli:main"
#bsamseth = "aoc_runner:plugin"

[tool.poetry.plugins."cli"]
foo = "cli"

[tool.pytest.ini_options]
testpaths = "tests/"

27 changes: 0 additions & 27 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import importlib


def solve(day, year, data):
moduleName = "aoc{}.day{}".format(year, day)
mod = importlib.import_module(moduleName)
part1 = mod.part1(data)
part2 = mod.part2(data)
return part1, part2
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion aoc_cas/aoc2019/day11.py → src/aoc2019/day11.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019.IntCodeComputer import IntCodeComputerVM
from aoc2019.IntCodeComputer import IntCodeComputerVM
from collections import defaultdict

BLACK = 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion aoc_cas/aoc2019/day21.py → src/aoc2019/day21.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019.IntCodeComputer import IntCodeComputerVM, read_program
from aoc2019.IntCodeComputer import IntCodeComputerVM, read_program


def instructions(*inputs):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/aoc2020/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/aoc2021/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/aoc2023/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions src/aoc2023/day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def part1(data):
def get_edge_sum(line):
digits = [int(char) for char in line if char.isdigit()]
res = digits[0] * 10 + digits[-1]
return res

return sum(map(get_edge_sum, data.splitlines()))


def part2(data):
spelled_out = {
"1": 1,
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 8,
"9": 9,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9,
}
result = 0
for line in data.splitlines():
left_digit = min(((line + k).find(k), v) for k, v in spelled_out.items())[1]
right_digit = max((line.rfind(k), v) for k, v in spelled_out.items())[1]
result += 10 * left_digit + right_digit
return result


if __name__ == "__main__":
from aocd import get_data

data = get_data(year=2023, day=1)
print(part1(data))
print(part2(data))
8 changes: 8 additions & 0 deletions src/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import importlib

# def solve(day, year, data):
# moduleName = "aoc{}.day{}".format(year, day)
# mod = importlib.import_module(moduleName)
# part1 = mod.part1(data)
# part2 = mod.part2(data)
# return part1, part2
44 changes: 44 additions & 0 deletions src/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# import argparse
# import importlib
# from aocd import get_data
# parser = argparse.ArgumentParser(description="Process some integers.")
# parser.add_argument("--year", "-y", type=int, default=2021)
# parser.add_argument("--day", "-d", type=int)
# parser.add_argument("--file", "-f", type=argparse.FileType("r"))
#
# args = parser.parse_args()
#
#
#
#
# def main():
# moduleName = "aoc{}.day{}".format(args.year, args.day)
# try:
# mod = importlib.import_module(moduleName)
# except:
# raise Exception(f"Unable to load module %s" % moduleName)
# if args.file:
# data = args.file.read()
# else:
# data = get_data(day=args.day, year=args.year)
# part1 = mod.part1(data)
# part2 = mod.part2(data)
#
# return part1, part2
#
#
# if __name__ == "__main__":
# print(main())


import click


@click.command()
def mycommand():
"""Your command description."""
# Your command logic here
print("Running my command...")


print("poop")
Empty file added tests/2019/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019 import day16 as aoc
from aoc2019 import day16 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019 import day20 as aoc
from aoc2019 import day20 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019 import day22 as aoc
from aoc2019 import day22 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2019 import day7 as aoc
from aoc2019 import day7 as aoc


def testPart1():
Expand Down
Empty file added tests/2020/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import aoc_cas.aoc2020.day1 as aoc
import aoc2020.day1 as aoc

testData1 = """
1721
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day10 as aoc
from aoc2020 import day10 as aoc


data = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day11 as aoc
from aoc2020 import day11 as aoc


data = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day12 as aoc
from aoc2020 import day12 as aoc


data = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day13 as aoc
from aoc2020 import day13 as aoc


data = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day14 as aoc
from aoc2020 import day14 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day15 as aoc
from aoc2020 import day15 as aoc
import pytest


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day16 as aoc
from aoc2020 import day16 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day17 as aoc
from aoc2020 import day17 as aoc


data = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day18 as aoc
from aoc2020 import day18 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day19 as aoc
from aoc2020 import day19 as aoc

data1 = """
0: 4 1 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import aoc_cas.aoc2020.day2 as aoc
import aoc2020.day2 as aoc

testData = """
1-3 a: abcde
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day20 as aoc
from aoc2020 import day20 as aoc


def testPart1():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aoc_cas.aoc2020 import day21 as aoc
from aoc2020 import day21 as aoc

data = """
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
Expand Down
Loading

0 comments on commit 36a3600

Please sign in to comment.