Skip to content

Instantly share code, notes, and snippets.

@aramperes
Last active December 20, 2024 01:25
Show Gist options
  • Save aramperes/4b52147128e36beef109a65e5d825da9 to your computer and use it in GitHub Desktop.
Save aramperes/4b52147128e36beef109a65e5d825da9 to your computer and use it in GitHub Desktop.
Advent of Code 2024 Day 1 - Bash
#!/bin/bash
dbg="+x"
set "$dbg"
in="$1"
awk '{print $1}' "$in" |\
sort |\
nl -bt -nln |\
xargs -I '{}' bash $dbg -c "\\
awk '{print \$2}' \"$in\" |\\
sort |\\
tail -n+\$(\\
echo -n '{}' | awk '{printf \$1}'\\
) |\\
head -1 |\\
awk \"{printf \\\"\\
(\$(echo -n {} | cut -d' ' -f2)-%s)\\\", \\\$1\\
}\" |\\
xargs -I '@@' bash $dbg -c '\\
echo \$(@@) |\\
tr -d -
'
" |\
xargs |\
sed -e 's/\ /+/g' |\
xargs -I '{}' bash $dbg -c 'echo $(({}))'
#!/bin/bash
dbg="+x"
set "$dbg"
in="$1"
awk '{print $1}' "$1" |\
xargs -I '{}' bash $dbg -c "\\
awk '\$2 == \"{}\"' \"$in\" |\\
wc -l |\\
xargs -0 printf \"{}*%s\"
" |\
xargs |\
sed -e 's/\ /+/g' |\
xargs -I '{}' bash $dbg -c 'echo $(({}))'
3 4
4 3
2 5
1 3
3 9
3 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment