other cool repos + 07 online solutions

This commit is contained in:
yosh 2022-12-09 15:03:45 -05:00
parent 8fbf90abed
commit faad2db537
3 changed files with 69 additions and 0 deletions

33
07_ONLINE_01_p1.awk Normal file
View File

@ -0,0 +1,33 @@
# https://old.reddit.com/r/adventofcode/comments/zesk40/2022_day_7_solutions/iz8ppox/?context=3
{
# checked: / only occurs on first line:
if ($0 ~ /^\$ cd \//)
# root dir = #1 ; debug: name[1] = "/"
at = i = 1
else if ($0 ~ /^\$ cd \.\./)
at = up[at]
else if ($0 ~ /^\$ cd/) {
up[++i] = at
at = i # debug: name[i] = $3
}
else if ($1 ~ /^[0-9]+$/)
tot[at] += $1
}
END {
# add subdir totals
for (i in up) {
at = i
while (at != 1) {
tot[up[at]] += tot[i]
at = up[at]
}
}
for (i in tot) {
if (tot[i] <= 100000)
sumtot += tot[i]
}
print sumtot
}

34
07_ONLINE_01_p2.awk Normal file
View File

@ -0,0 +1,34 @@
# https://old.reddit.com/r/adventofcode/comments/zesk40/2022_day_7_solutions/iz8ppox/?context=3
{
# checked: / only occurs on first line:
if ($0 ~ /^\$ cd \//)
# root dir = #1 ; debug: name[1] = "/"
at = i = 1
else if ($0 ~ /^\$ cd \.\./)
at = up[at]
else if ($0 ~ /^\$ cd/) {
up[++i] = at
at = i # debug: name[i] = $3
}
else if ($1 ~ /^[0-9]+$/)
tot[at] += $1
}
END {
# add subdir totals
for (i in up) {
at = i
while (at != 1) {
tot[up[at]] += tot[i]
at = up[at]
}
}
PROCINFO["sorted_in"] = "@val_num_asc"
for (i in tot)
if (((70000000 - tot[1]) + tot[i]) > 30000000) {
print tot[i]
exit 0
}
}

2
other-cool-repos.md Normal file
View File

@ -0,0 +1,2 @@
# Other Cool AOC2022 Repos
- https://github.com/TOTBWF/advent-of-code-2022