#!/usr/bin/env tclsh9.0 namespace import ::tcl::mathop::* namespace import ::tcl::mathfunc::* set blinks 25 if {[llength $argv] == 1} {set blinks [lindex $argv 0]} proc input {} { global count set count [dict create] gets stdin line foreach s $line { dict incr count [int $s] } } proc blink {} { global count blinks for {set i 0} {$i < $blinks} {incr i} { set new [dict create] dict for {s n} $count { if {$s == 0} { dict incr new 1 $n } else { set d [digits $s] if {[% $d 2] == 0} { set tmp [** 10 [/ $d 2]] dict incr new [/ $s $tmp] $n dict incr new [% $s $tmp] $n } else { dict incr new [* $s 2024] $n } } } set count $new } } proc digits {n} { if {$n < 10} {return 1} if {$n < 100} {return 2} if {$n < 1000} {return 3} if {$n < 10000} {return 4} if {$n < 100000} {return 5} if {$n < 1000000} {return 6} return [int [+ [log10 $n] 1]] } proc output {} { global count set total 0 dict for {s n} $count { incr total $n } puts $total } input blink output