/ 2025 / 11 / p1.tri
p1.tri
 1  import "trilogy:debug" use dbg
 2  import "trilogy:io" use readlines
 3  import "trilogy:parsec" use parse, apply, word, sep_by_1, string, char
 4  import "trilogy:array" use fold, map
 5  import "trilogy:iterator" as it
 6  import "trilogy:record" as rec
 7  
 8  proc connection!() {
 9    let source = apply word
10    apply <| string ": "
11    let outputs = apply (sep_by_1 (char ' ') word)
12    return source:outputs
13  }
14  
15  func paths_from _ {||} = 0
16  func paths_from "out" _ = 1
17  func paths_from from {| ^from => to, ..rest |} =
18    fold (+) 0 <| map (fn to2. paths_from to2 rest) to
19  
20  proc main!() {
21    let graph = rec::collect <| it::map (parse connection) <| readlines
22    dbg!(paths_from "you" graph)
23  }