aoc2024

advent of code 2024 version unix - retour accueil

git clone git://bebou.netlib.re/aoc2024
Log | Files | Refs |

5.solve (591B)


      1 #! /bin/sh
      2 
      3 echo "part 1"
      4 
      5 csplit 5.input /^$/ > /dev/null
      6 orderfiles=xx00
      7 manualpages=xx01
      8 < $orderfiles sed -E 's/\|/.*/g' > rules
      9 cat $manualpages | grep -v ^$ |
     10 while read update;do
     11 	relevantrulesreg=$(echo "$update" |
     12 					grep -v ^$ |
     13 					sed 's/^/(/;s/$/)/p' |
     14 					tr ',' '|' |
     15 					paste -s -d '.' | sed 's/\./\\.\\*/' )
     16 	relevantrules=$(< rules grep -E "$relevantrulesreg")
     17 	greps=$(echo "$relevantrules" | sed -E 's/^/grep "/;s/$/"/' |
     18 		paste -s -d'|')
     19 	echo "$update" | eval $greps
     20 done | awk -F',' '{mid=(NF+1)/2;print $mid}' | paste -s -d+ | bc
     21 
     22 echo "part 2"
     23 
     24 rm xx00 xx01
     25