Day 04 - original solution

This commit is contained in:
yosh 2022-12-04 04:17:55 -05:00
parent 5258095239
commit 08069ac273
3 changed files with 1020 additions and 0 deletions

19
04.sh Executable file
View File

@ -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"

1000
04_input Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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)