Created
June 18, 2009 16:07
-
-
Save Koitaro/131975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace path {::tcl::mathop ::tcl::mathfunc} | |
proc primes n { | |
set half [/ [- $n 1] 2] | |
set xs [lrepeat $half 1] | |
set p 0; set root [/ [sqrt $n] 2] | |
while {$p < $root} { | |
if {[lindex $xs $p]} { | |
set step [+ [* 2 $p] 3] | |
set index [+ $p $step] | |
while {$index < $half} { lset xs $index 0; incr index $step } | |
} | |
incr p | |
} | |
set answer 2 | |
foreach i [lsearch -all $xs 1] { lappend answer [+ [* 2 $i] 3] } | |
set answer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment