other cool repos + 07 online solutions
This commit is contained in:
parent
8fbf90abed
commit
faad2db537
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
# Other Cool AOC2022 Repos
|
||||
- https://github.com/TOTBWF/advent-of-code-2022
|
Loading…
Reference in New Issue