Day 04 - original solution
This commit is contained in:
parent
5258095239
commit
08069ac273
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
ng=0; no=0
|
||||
IFS=",-"
|
||||
while read -r l; do
|
||||
set -- $l
|
||||
r1=$(($2-$1))
|
||||
r2=$(($4-$3))
|
||||
d=$((r2-r1))
|
||||
o=$(($3-$1))
|
||||
e=$((d+o))
|
||||
|
||||
# p1
|
||||
{ { [ "$e" -ge 0 ] && [ "$e" -le "$d" ]; } || { [ "$e" -le 0 ] && [ "$e" -ge "$d" ]; }; } && ng=$((ng+1))
|
||||
|
||||
# p2
|
||||
{ { [ "$o" -ge 0 ] && [ "$o" -le "$r1" ]; } || { [ "$o" -lt 0 ] && [ "${o#-}" -le "$r2" ]; }; } && no=$((no+1))
|
||||
done < 04_input
|
||||
echo "$ng"
|
||||
echo "$no"
|
|
@ -8,3 +8,4 @@ this repo will also include online solutions that I think are neat, indicated by
|
|||
1. awk (uses features exclusive to GNU's implementation, gawk)
|
||||
2. shell (completely POSIX-conforming implementation)
|
||||
3. awk (POSIX-conforming)
|
||||
4. shell (POSIX, no utilities except `echo` and `read` used)
|
||||
|
|
Loading…
Reference in New Issue