Skip to content

Instantly share code, notes, and snippets.

@ljyang
Created December 5, 2022 22:27
Show Gist options
  • Save ljyang/090a0e53ffcbe4405cfea617726708dc to your computer and use it in GitHub Desktop.
Save ljyang/090a0e53ffcbe4405cfea617726708dc to your computer and use it in GitHub Desktop.
day4
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