Compare commits

..

No commits in common. "f1907db70c912c43c73e78827be822ef8b382a23" and "c1ac5a1c543d87f60a89c5de3aad4591abd3a020" have entirely different histories.

7 changed files with 0 additions and 1132 deletions

View file

@ -1,12 +0,0 @@
* Advent of Code Python
** Day 1
#+begin_src shell
source ~/virtualenvs/aoc-2023/bin/activate
cd ~/git/advent-of-code/python/2023
python src/andy_aoc_2023/day1.py src/andy_aoc_2023/day1_big
#+end_src
*** Answers
54573
54591

View file

@ -1,25 +0,0 @@
[project]
name = "andy_aoc_2023"
version = "0.0.1"
dependencies = [
"",
]
authors = [
{ name="Andy Lu" },
]
description = "All of my code for 2023"
readme = "README.org"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
Homepage = "https://github.com/luandy64/advent-of-code"
Issues = "https://github.com/luandy64/advent-of-code/issues"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

View file

@ -1,84 +0,0 @@
from functools import reduce
from operator import add
import re
import sys
NUMBERS = {
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
}
WORDS = {
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9",
}
BOTH = {**WORDS, **NUMBERS}
def get_numbers(line, parse_words=False):
if parse_words:
return re.findall(rf"(?=({'|'.join(BOTH)}))", line)
return re.findall("|".join(NUMBERS.keys()), line)
def line_to_number(line, parse_words=False):
string_nums = get_numbers(line, parse_words)
if parse_words:
lookup = BOTH
else:
lookup = NUMBERS
first = lookup[string_nums[0]]
last = lookup[string_nums[-1]]
number = first + last
return int(number)
def part1(lines):
nums = map(line_to_number,
lines)
answer = reduce(add,
nums)
print(answer)
def part2(lines):
nums = map(lambda x: line_to_number(x, parse_words=True),
lines)
answer = reduce(add,
nums)
print(answer)
if __name__ == "__main__":
input_file = sys.argv[1]
with open(input_file) as infile:
input_lines = [
line.strip()
for line in infile.readlines()
]
part1(input_lines)
part2(input_lines)

File diff suppressed because it is too large Load diff

View file

@ -1,4 +0,0 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

View file

@ -1,7 +0,0 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen