Well that was easy. I just progressively filtered the list with each datum from the target (the analyser’s output). Again, Angort is good for this sort of thing, as is any language with decent functional and collection capabilities:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
require "util.ang" import `io library drop `regex library drop :mkaunt |n,l:i,this| ?l mkiter dup !i ifirst [% `n ?n] { ?i idone ifleave ?i icur tosymbol ?i inext ?i icur toint, ?i inext } ; # this is the target [%`children 3, `cats 7, `samoyeds 2, `pomeranians 3, `akitas 0, `vizslas 0, `goldfish 5, `trees 3, `cars 2, `perfumes 1] !Target # read and parse input ( [] !Aunts "day16in" "r" io$open each { i <<"([:,]|\\s)+" regex$compile>> regex$split dup snd toint swap 2 -1 slice mkaunt ?Aunts push } )@ # part 1 (|:l,k,v| ?Aunts deepclone !l ?Target each { ?l len. i !k ival !v ?l (|a:w| ?k ?a get !w ?w isnone ?w ?v = or) filter !l } "Part 1 result = "p ?l fst?`n. ?l show. )@ # part 2 [`cats,`trees] !MoreThan [`pomeranians,`goldfish] !LessThan (|:l,k,v| ?Aunts deepclone !l ?Target each { ?l len. i !k ival !v # v is target data ?l (|a:w| ?k ?a get !w # w is data in aunt ?w isnone if 1 stop then cases ?k ?MoreThan in if ?w ?v > case ?k ?LessThan in if ?w ?v < case ?w ?v = otherwise ) filter !l } "Part 2 result = "p ?l fst?`n. ?l show. )@ quit |