#!/usr/bin/env tclsh8.6 set maptype {} while {[gets stdin line] >= 0} { if {! [string length $line]} continue if {[string match seeds:* $line]} { set seeds [lindex [split $line :] 1] } elseif {[string match {*-to-* map:} $line]} { set maptype [lindex [split $line -] 0] set $maptype [list] } else { lappend $maptype $line } } proc match {map key} { foreach range $map { lassign $range dstart sstart len if {$key >= $sstart && $key < $sstart + $len} { return [expr {$dstart + $key - $sstart}] } } return $key } set lowest {} foreach s $seeds { set loc [match $humidity [match $temperature [match $light \ [match $water [match $fertilizer [match $soil [match $seed $s]]]]]]] if {$lowest eq {} || $lowest > $loc} {set lowest $loc} } puts $lowest