Created
December 5, 2022 22:27
-
-
Save ljyang/090a0e53ffcbe4405cfea617726708dc to your computer and use it in GitHub Desktop.
day4
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
part1 | |
#!/bin/bash | |
declare -i count | |
count = 0 | |
sed 's/,/ /g' day4.txt | sed 's/-/ /g' >split.txt | |
file="split.txt" | |
while read -r a1 a2 b1 b2; do | |
if [ $a1 -le $b1 -a $a2 -ge $b2 ] || [ $a1 -ge $b1 -a $a2 -le $b2 ]; | |
then | |
count+=1 | |
fi | |
done <$file | |
echo "$count" | |
part2 | |
#!/bin/bash | |
declare -i count | |
count = 0 | |
sed 's/,/ /g' day4.txt | sed 's/-/ /g' >split.txt | |
file="split.txt" | |
while read -r a1 a2 b1 b2; do | |
if [ $a1 -le $b1 -a $a2 -ge $b2 ] || [ $a1 -ge $b1 -a $a2 -le $b2 ] || [ $a2 -ge $b1 -a $a1 -le $b2 ] || [ $b2 -ge $a1 -a $b1 -le $a2 ]; | |
then | |
count+=1 | |
fi | |
done <$file | |
echo "$count" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment