Skip to content

Instantly share code, notes, and snippets.

@sylr
Created December 3, 2023 19:42
Show Gist options
  • Save sylr/c372fc94ca7bbdc5a53793365240dbd5 to your computer and use it in GitHub Desktop.
Save sylr/c372fc94ca7bbdc5a53793365240dbd5 to your computer and use it in GitHub Desktop.
aoc-2023-day-01
echo "+/" $(sed -e 's/[^0-9]//g' -e 's/^\(.\)$/\1\1/' -e 's/^\(.\).*\(.\)$/\1\2/' ~/aoc-1.input) | ivy
#!/usr/bin/awk -f
BEGIN { total = 0 }
{
a=""
b=""
$0=$0$0
for (i=1; i <= length($0); i++) {
t = substr($0, 1, i)
if (t ~ /[1-9]/) { a = substr($0, i, 1); break; }
if (t ~ /one/) { a = 1; break; }
if (t ~ /two/) { a = 2; break; }
if (t ~ /three/) { a = 3; break; }
if (t ~ /four/) { a = 4; break; }
if (t ~ /five/) { a = 5; break; }
if (t ~ /six/) { a = 6; break; }
if (t ~ /seven/) { a = 7; break; }
if (t ~ /eight/) { a = 8; break; }
if (t ~ /nine/) { a = 9; break; }
}
for (i=length($0); 0 < i; i--) {
t = substr($0, i, length($0)-i+1)
if (t ~ /[1-9]/) { b = substr($0, i, 1); break; }
if (t ~ /one/) { b = 1; break; }
if (t ~ /two/) { b = 2; break; }
if (t ~ /three/) { b = 3; break; }
if (t ~ /four/) { b = 4; break; }
if (t ~ /five/) { b = 5; break; }
if (t ~ /six/) { b = 6; break; }
if (t ~ /seven/) { b = 7; break; }
if (t ~ /eight/) { b = 8; break; }
if (t ~ /nine/) { b = 9; break; }
}
total = total + sprintf("%s%s", a, b)
}
END { printf("%d\n", total) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment