Paste: aoc7

Author: jon
Mode: factor
Date: Mon, 7 Dec 2020 09:25:20
Plain Text |
"/tmp/input" ascii file-lines [
  " " split { "contain" } split first2
  [ but-last " " join ] [
    4 group
    [ first3 2array
      [ string>number ] [ " " join ] bi* 2array
    ] map
  ] bi* 2array
] map
H{ } clone [
  [ [ first2 ] dip [ [ second ] dip push-at ] curry with each ] curry each
] keep
{ "shiny gold" } [ [ of ] with map concat members ] with follow concat members
length 1 - .

MEMO: bags ( root hash -- n )
[ at ] keep [ [ first2 ] dip foo 1 + * ] curry map-sum ;
"/tmp/input" ascii file-lines [
  " " split { "contain" } split first2
  [ but-last " " join ] [
    4 group
    [ first3 2array
      [ string>number ] [ " " join ] bi* 2array
      dup first [ drop f ] unless
    ] map harvest
  ] bi*
] H{ } map>assoc
"shiny gold" swap bags .

New Annotation

Summary:
Author:
Mode:
Body: