diff options
Diffstat (limited to '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 |