Initial commit / Day 01 / Day 02
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
venv
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (python-aoc-2020)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal 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-2020.iml" filepath="$PROJECT_DIR$/.idea/python-aoc-2020.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/python-aoc-2020.iml
generated
Normal file
10
.idea/python-aoc-2020.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
2000
day01/input.txt
Normal file
2000
day01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
13
day01/part1.py
Normal file
13
day01/part1.py
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (int(x.strip()) for x in open("input.txt"))
|
||||
|
||||
last = float('inf')
|
||||
cnt = 0
|
||||
|
||||
for line in lines:
|
||||
if last < line:
|
||||
cnt += 1
|
||||
last = line
|
||||
|
||||
print(cnt)
|
||||
14
day01/part2.py
Normal file
14
day01/part2.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (int(x.strip()) for x in open("input.txt"))
|
||||
|
||||
last = [float('inf')] * 3
|
||||
cnt = 0
|
||||
|
||||
for line in lines:
|
||||
nxt = last[1:] + [line]
|
||||
if sum(last) < sum(nxt):
|
||||
cnt += 1
|
||||
last = nxt
|
||||
|
||||
print(cnt)
|
||||
1000
day02/input.txt
Normal file
1000
day02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
17
day02/part1.py
Normal file
17
day02/part1.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
hor = 0
|
||||
depth = 0
|
||||
for line in lines:
|
||||
cmd, strVal = line.split(" ")
|
||||
val = int(strVal)
|
||||
if cmd == 'forward':
|
||||
hor += val
|
||||
elif cmd == 'down':
|
||||
depth += val
|
||||
else:
|
||||
depth -= val
|
||||
|
||||
print(hor*depth)
|
||||
19
day02/part2.py
Normal file
19
day02/part2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
hor = 0
|
||||
depth = 0
|
||||
aim = 0
|
||||
for line in lines:
|
||||
cmd, strVal = line.split(" ")
|
||||
val = int(strVal)
|
||||
if cmd == 'forward':
|
||||
hor += val
|
||||
depth += aim * val
|
||||
elif cmd == 'down':
|
||||
aim += val
|
||||
else:
|
||||
aim -= val
|
||||
|
||||
print(hor*depth)
|
||||
29
newday.sh
Normal file
29
newday.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
# 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/2021/day/$(echo $1 | sed 's/^0*//')/input"\
|
||||
--output "$f/input.txt"
|
||||
Reference in New Issue
Block a user