This commit is contained in:
Sebastian Seedorf
2023-12-05 13:26:55 +01:00
commit 6cdcb4e260
11 changed files with 1115 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.env
venv

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10.12 WSL (Ubuntu-22.04): (/home/sese/projects/python-aoc-2023/.venv/bin/python)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10.12 WSL (Ubuntu-22.04): (/home/sese/projects/python-aoc-2023/.venv/bin/python)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/python-aoc-2023.iml" filepath="$PROJECT_DIR$/.idea/python-aoc-2023.iml" />
</modules>
</component>
</project>

12
.idea/python-aoc-2023.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1000
day01/input.txt Normal file

File diff suppressed because it is too large Load Diff

14
day01/part1.py Normal file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env python3
import re
lines = (x.strip() for x in open("input.txt"))
total = 0
regexFirst = re.compile(f"^.*?(\\d)")
regexLast = re.compile(f"^.*(\\d)")
for line in lines:
first = regexFirst.match(line).group(1)
last = regexLast.match(line).group(1)
total += int(first + last)
print(total)

20
day01/part2.py Normal file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import re
STRINGS = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
lines = (x.strip() for x in open("input.txt"))
total = 0
digitRegex = f"(\\d|{'|'.join(STRINGS)})"
regexFirst = re.compile(f"^.*?(\\d|{'|'.join(STRINGS)})")
regexLast = re.compile(f"^.*(\\d|{'|'.join(STRINGS)})")
def parse(value):
return str(STRINGS.index(value) + 1) if value in STRINGS else value
for line in lines:
first = parse(regexFirst.match(line).group(1))
last = parse(regexLast.match(line).group(1))
total += int(first + last)
print(total)

32
newday.sh Executable file
View File

@@ -0,0 +1,32 @@
# load .env
if [ -f .env ]; then
set -o allexport; source .env; set +o allexport
fi
# Create dir / abort if exists
f="day$(printf %02d $1)"
echo "$f"
mkdir "$f"
if [ $? -ne 0 ]; then { echo "$f already exists" ; exit 1; } fi
# create part files with template
txt=$(cat <<EOF
#!/usr/bin/env python3
lines = (x.strip() for x in open("input.txt"))
for line in lines:
pass
EOF
)
echo "$txt" > "$f/part1.py"
echo "$txt" > "$f/part2.py"
# fetch input (set AOC_SESSION in .env file or as env var)
curl --request GET -sL \
--cookie "session=$AOC_SESSION" \
--url "https://adventofcode.com/2023/day/$(echo $1 | sed 's/^0*//')/input"\
--output "$f/input.txt"
# git
git add "$f/*"