summaryrefslogtreecommitdiffstats
path: root/nacl/demo/rowland.natcl
blob: 11e4cf134e567c72a20b40149224a25a6d8be673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
proc tcl::mathfunc::gcd {a b} { 
     while {$b} {set b [expr {$a % [set a $b]}]} 
     return $a 
}
# Rowland's: compute a(n)-a(n-1) where a(1)=7 and 
#   a(n) = a(n – 1) + gcd(n, a(n – 1)) 

proc rowland m {
    set a 7   
    set n 1 
    set out {}
    while {$n<=$m} { 
	incr n 
	set b $a 
	set a [expr {$b+gcd($n,$b)}] 
	set p [expr {$a-$b}] 
	if {$p>1} {lappend out $p} 
    }
    return $out
}