-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sf
48 lines (33 loc) · 1.59 KB
/
generate.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/ruby
# a(n) is the least k such that the denominators of continued fraction convergents for sqrt(k) match the first n Fibonacci numbers.
# https://oeis.org/A309666
# See also:
# https://oeis.org/A309666
# https://oeis.org/A071296
var max = 1407271538
var nterms = 26
var terms = Hash()
for n in (1..nterms) {
say "Processing #{n}..."
var ones = n.of(1)
var fibs = n.of{fib(_+1)}
for k in (1 .. max.isqrt) {
var z = round([k, ones...].cfrac2num**2)
if (z.isqrt == k) {
if (z.sqrt.convergents(n).map{.de} == fibs) {
terms{n} := [] << z
break
}
}
}
}
for n in (1..nterms) {
print(terms.has(n) ? terms{n}.min : '?', ", ")
}
say ''
__END__
round: ?, ?, 7, 7, 13, 58, 58, 135, 819, 819, 2081, 13834, 13834, 35955, 244647, 244647, 639389, 4374866, 4374866, 11448871, 78439683, 78439683, 205337953, 1407271538, 1407271538, ?,
ceil: 3, 3, 7, 7, ?, 135, 135, 135, 819, 819, ?, 35955, 35955, 35955, 244647, 244647, ?, ?, ?, ?, ?, ?, ?, ?, ?,
floor: 2, ?, 13, 13, 13, 58, 58, ?, 2081, 2081, 2081, 13834, 13834, ?, 639389, 639389, 639389, 4374866, 4374866, ?, ?, ?, ?, ?, ?,
A060215 = {3, 7, 7, 13, 58, 58, 135, 461, 819, 2081, 13624, 13834, 35955, 95773, 244647, 639389, 1798800, 4374866, 11448871, 30002701, 78439683, 205337953, 541653136, ...}
A071296 = {3, 0, 7, 13, 0, 58, 135, 0, 819, 2081, 0, 13834, 35955, 0, 244647, 639389, 0, 4374866, 11448871, 0, 78439683, 205337953, 0, 1407271538, 3684200835, 0, 25251313255, 66108441037, 0, 453111560266, 1186259960295, 0, 8130736409715, 21286537898177, 0, ...}