#!/usr/bin/env tclsh set y 0 while {[gets stdin line] >= 0} { if {$line eq {}} continue set x 0 foreach c [split $line {}] { set grid($x,$y) $c incr x } set width $x incr y } set height $y proc trees {right down} { global grid width height set x 0 set y $down set n 0 while {$y < $height} { set x [expr {($x+$right) % $width}] if {$grid($x,$y) eq "#"} {incr n} incr y $down } return $n } lappend list [trees 1 1] lappend list [trees 3 1] lappend list [trees 5 1] lappend list [trees 7 1] lappend list [trees 1 2] puts [::tcl::mathop::* {*}$list]