#!/usr/bin/env tclsh8.6 namespace import ::tcl::mathop::* set card 1 lappend count 0 while {[gets stdin line] >= 0} { set line [lindex [split $line :] 1] lassign [split $line |] win($card) has($card) lappend count 1 incr card } for {set c 1} {$c < $card} {incr c} { array unset winhash foreach n $win($c) {set winhash($n) 1} set score 0 foreach n $has($c) { if {[info exists winhash($n)]} {incr score} } for {set i [+ $c 1]} {$i <= [+ $c $score]} {incr i} { # incr count($i) $count($c) lset count $i [+ [lindex $count $i] [lindex $count $c]] } } puts [+ {*}$count]