Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Calkin-Wilf-sequence/Sidef/calkin-wilf-sequence.sidef
Normal file
21
Task/Calkin-Wilf-sequence/Sidef/calkin-wilf-sequence.sidef
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
func calkin_wilf(n) is cached {
|
||||
return 1 if (n == 1)
|
||||
1/(2*floor(__FUNC__(n-1)) + 1 - __FUNC__(n-1))
|
||||
}
|
||||
|
||||
func r2cw(r) {
|
||||
|
||||
var cfrac = r.as_cfrac
|
||||
cfrac.len.is_odd || return nil
|
||||
|
||||
Num(cfrac.flip.map_kv {|k,v| (k.is_odd ? '0' : '1') * v }.join, 2)
|
||||
}
|
||||
|
||||
with (20) {|n|
|
||||
say "First #{n} terms of the Calkin-Wilf sequence:"
|
||||
say calkin_wilf.map(1..n)
|
||||
}
|
||||
|
||||
with (83116/51639) {|r|
|
||||
say ("\n#{r.as_rat} is at index: ", r2cw(r))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue