Posted to tcl by libertas at Mon Dec 07 22:20:32 GMT 2020view raw
- # Error:
- # 0 -> dark blue contains: {2 {dark violet}}
- # .... 2 .... dark violet
- # 0 -> dark violet contains: {0 {other bags.}}
- # .... 0 .... other bags.
- # 7 !!!!!!!!!!!!!!!!!!
- # can't use empty string as operand of "*"
- # while executing
- # "expr {$::cnt + $nr + $nr * [compute2 $b]}"
- # (procedure "compute2" line 9)
- #!/usr/bin/env tclsh
- set lall [list {shiny gold} {{2 {dark red}} {2 {dark pink}}} {dark red} {{2 {dark orange}}} {dark orange} {{2 {dark yellow}}} {dark yellow} {{2 {dark green}}} {dark green} {{2 {dark blue}}} {dark blue} {{2 {dark violet}}} {dark violet} {{0 {other bags.}}} {dark pink} {{2 {dark violet}}}]
- set all [dict create {*}$lall]
- set cnt 0
- proc compute2 {tp} {
- set contains [dict get $::all $tp]
- puts "$::cnt -> $tp contains: $contains "
- foreach bagset $contains {
- set nr [lindex $bagset 0]
- set b [lindex $bagset 1]
- puts " .... $nr .... $b"
- if {$nr != 0} {
- set ::cnt [expr {$::cnt + $nr + $nr * [compute2 $b]}]
- } else {puts "[info level] !!!!!!!!!!!!!!!!!!"; return 0}
- }
- }
- puts ">> [compute2 "shiny gold"]"
- puts "day 07 part2: $cnt"