Skip to content

Instantly share code, notes, and snippets.

@ramiror
Created December 8, 2021 00:27
Show Gist options
  • Save ramiror/38fe083d3d35273f2b5798ccd16af7e0 to your computer and use it in GitHub Desktop.
Save ramiror/38fe083d3d35273f2b5798ccd16af7e0 to your computer and use it in GitHub Desktop.
# part 1
awk '
/forward/ { x += $2 }
/up/ {y-=$2}
/down/ {y+=$2}
END {print x*y}
' input.txt
# part 2
awk '
/forward/ {x+=$2;y+=$2*aim}
/up/ {aim-=$2}
/down/ {aim+=$2}
END {print x*y}
' input.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment