Anonymous user
Pythagorean triples: Difference between revisions
m
→{{header|Tcl}}: Remove coroutines (and version restriction); not needed any more
m (→{{header|Tcl}}: Smarter still by avoiding recursion; queue is not culled during generation, _much_ slower to do that) |
m (→{{header|Tcl}}: Remove coroutines (and version restriction); not needed any more) |
||
Line 883:
=={{header|Tcl}}==
Using the efficient method based off the Wikipedia article:
lappend q 3 4 5
set idx [set count [set prim 0]]
while {$idx < [llength $q]} {
set a [lindex $q $idx]
Line 894 ⟶ 892:
incr idx
if {$a + $b + $c <= $limit} {
incr prim
for {set i
}
lappend q \
Line 904 ⟶ 902:
}
}
return
▲proc countPythagoreanTriples n {
▲ incr count
}
for {set i 10} {$i <= 10000000} {set i [expr {$i*10}]} {
lassign [
puts "perimeter limit $i => $count triples, $primitive primitive"
}</lang>
|