Skip to content

Instantly share code, notes, and snippets.

@umglurf
Created December 1, 2020 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umglurf/4056b4593a5adbce33da93cf1f2c9a4f to your computer and use it in GitHub Desktop.
Save umglurf/4056b4593a5adbce33da93cf1f2c9a4f to your computer and use it in GitHub Desktop.
AoC 2020 day 1 bash
#!/bin/bash
tmpfile=$(mktemp)
cat input-day1 > "$tmpfile"
for num1 in $(< "$tmpfile" )
do
sed -ri "/^$num1$/d" "$tmpfile"
for num2 in $(< "$tmpfile" )
do
if [ $num1 -eq $num2 ]
then
continue
fi
if [ $(( num1 + num2 )) -eq 2020 ]
then
echo "Found ${num1} + ${num2} = 2020, product = $(( num1 * num2 ))"
fi
done
done
rm -- "$tmpfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment