September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
22
Task/Stern-Brocot-sequence/R/stern-brocot-sequence.r
Normal file
22
Task/Stern-Brocot-sequence/R/stern-brocot-sequence.r
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
## Stern-Brocot sequence
|
||||
## 12/19/16 aev
|
||||
SternBrocot <- function(n){
|
||||
V <- 1; k <- n/2;
|
||||
for (i in 1:k)
|
||||
{ V[2*i] = V[i]; V[2*i+1] = V[i] + V[i+1];}
|
||||
return(V);
|
||||
}
|
||||
|
||||
## Required tests:
|
||||
require(pracma);
|
||||
{
|
||||
cat(" *** The first 15:",SternBrocot(15),"\n");
|
||||
cat(" *** The first i@n:","\n");
|
||||
V=SternBrocot(40);
|
||||
for (i in 1:10) {j=match(i,V); cat(i,"@",j,",")}
|
||||
V=SternBrocot(1200);
|
||||
i=100; j=match(i,V); cat(i,"@",j,"\n");
|
||||
V=SternBrocot(1000); j=1;
|
||||
for (i in 2:1000) {j=j*gcd(V[i-1],V[i])}
|
||||
if(j==1) {cat(" *** All GCDs=1!\n")} else {cat(" *** All GCDs!=1??\n")}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue