#!/usr/bin/env tclsh8.6 while {[gets stdin line] >= 0} { if {$line eq ""} continue if {[scan $line {%d,%d -> %d,%d} x1 y1 x2 y2] != 4} continue if {$y1 == $y2} { if {$x1 > $x2} {set t $x1; set x1 $x2; set x2 $t} for {set i $x1} {$i <= $x2} {incr i} { incr grid($i,$y1) } } elseif {$x1 == $x2} { if {$y1 > $y2} {set t $y1; set y1 $y2; set y2 $t} for {set i $y1} {$i <= $y2} {incr i} { incr grid($x1,$i) } } } set n 0 foreach {key val} [array get grid] { if {$val >= 2} {incr n} } puts $n