Created
December 1, 2020 17:50
-
-
Save umglurf/4056b4593a5adbce33da93cf1f2c9a4f to your computer and use it in GitHub Desktop.
AoC 2020 day 1 bash
This file contains 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 | |
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