Created
December 20, 2024 02:28
-
-
Save aramperes/d93b38924ae0ccc2b9e518491906fae2 to your computer and use it in GitHub Desktop.
Advent of Code 2024 Day 3 - Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# cat input.txt | ./solve1.sh | |
grep -Po 'mul\(\d+,\d+\)' | | |
sed -r 's/^mul\(([0-9]+),([0-9]+)\)$/\1*\2/' | | |
xargs | | |
sed -e 's/\ /+/g' | | |
xargs -I @@ bash -c 'echo $((@@))' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# cat input.txt | ./solve2.sh | |
grep -Po "(mul\(\d+,\d+\))|(do\(\))|(don't\(\))" | | |
tr -d "'" | | |
xargs | | |
while read -r orig; do | |
echo "$orig" | | |
grep -Po 'dont\(\) .*?do\(\)' | | |
while read -r rm; do | |
echo "$rm" | | |
grep -Po 'mul\(\d+,\d+\)' | | |
sed -r 's/^mul\(([0-9]+),([0-9]+)\)$/\1*\2/' | | |
xargs | | |
sed -e 's/\ /+/g' | | |
xargs -I @@ bash -c 'echo $((@@))' | |
done | | |
paste -sd- - | | |
while read -r sub; do | |
echo "$orig" | | |
grep -Po 'mul\(\d+,\d+\)' | | |
sed -r 's/^mul\(([0-9]+),([0-9]+)\)$/\1*\2/' | | |
xargs | | |
sed -e 's/\ /+/g' | | |
xargs -I @@ bash -c 'echo $((@@))' | | |
while read -r sum; do | |
echo $(("$sum-$sub")) | |
done | |
done | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment