2倍を1000回繰り返すだけです。簡単ですね。
function fold($f, $x0) { begin { $x = $x0 } process { $x = &$f $x $_ } end { $x } } function twice($a) { $c = 0 foreach($e in $a) { $m = $e * 2 + $c if($m -lt 10) { $m $c = 0 } else { $m - 10 $c = 1 } } if($c -eq 1) { $c } } $N = 1000 (1..$N | fold { twice $args[0] $args[1] } @(1) | measure -sum).sum