diff options
author | Michael Hunteman <michael@huntm.net> | 2023-05-03 17:58:30 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2023-05-03 17:58:30 -0500 |
commit | 05286f41ce90a83ee7ed5c332651e0e1846c56ce (patch) | |
tree | 0cea6de713c5251d0ab7c95597b6bb2c817f1f0b | |
parent | 0a32d9ff56cdf0f2a669c21d7743b21ad72fe8f6 (diff) |
Add 4
-rwxr-xr-x | 4 | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +#!/bin/sh -eu +p1() ( + sum=0 + while IFS= read -r l + do + r1=$(printf "$l" | cut -d',' -f1) + r2=$(printf "$l" | cut -d',' -f2) + x1=$(printf "$r1" | cut -d'-' -f1) + y1=$(printf "$r1" | cut -d'-' -f2) + x2=$(printf "$r2" | cut -d'-' -f1) + y2=$(printf "$r2" | cut -d'-' -f2) + if ([ $x1 -le $x2 ] && [ $y1 -ge $y2 ]) || ([ $x2 -le $x1 ] && [ $y2 -ge $y1 ]) + then + sum=$((sum + 1)) + fi + done < input.txt + printf "%s\n" "$sum" +) + +p2() ( + sum=0 + while IFS= read -r l + do + r1=$(printf "$l" | cut -d',' -f1) + r2=$(printf "$l" | cut -d',' -f2) + x1=$(printf "$r1" | cut -d'-' -f1) + y1=$(printf "$r1" | cut -d'-' -f2) + x2=$(printf "$r2" | cut -d'-' -f1) + y2=$(printf "$r2" | cut -d'-' -f2) + if ([ $y1 -ge $x2 ] && [ $x1 -le $y2 ]) || ([ $y2 -ge $x1 ] && [ $x2 -le $y1 ]) + then + sum=$((sum + 1)) + fi + done < input.txt + printf "%s\n" "$sum" +) + +p1 +p2 |