#!/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) } } else { if {$x1 > $x2} { set tx $x1; set ty $y1 set x1 $x2; set y1 $y2 set x2 $tx; set y2 $ty } if {$y2 > $y1} {set dy 1} else {set dy -1} for {set i $x1; set j $y1} {$i <= $x2} {incr i; incr j $dy} { incr grid($i,$j) } } } if 0 { for {set j 0} {$j < 10} {incr j} { for {set i 0} {$i < 10} {incr i} { if {! [info exists grid($i,$j)]} {puts -nonewline .} \ else {puts -nonewline $grid($i,$j)} } puts "" } } set n 0 foreach {key val} [array get grid] { if {$val >= 2} {incr n} } puts $n