Sturmian word: Difference between revisions
Content added Content deleted
imported>CosmiaNebula (python, rational case) |
(Added Phix) |
||
Line 28: | Line 28: | ||
where <math>m/n</math> is the first continued fraction approximant to <math>\sqrt a</math> with a denominator <math>n \geq k</math> |
where <math>m/n</math> is the first continued fraction approximant to <math>\sqrt a</math> with a denominator <math>n \geq k</math> |
||
== |
== {{header|Phix}} == |
||
{{trans|Python}} |
|||
<!--(phixonline)--> |
|||
<syntaxhighlight lang="Phix"> |
|||
with javascript_semantics |
|||
function sturmian_word(integer m, n) |
|||
if m > n then |
|||
return sq_sub('0'+'1',sturmian_word(n,m)) |
|||
end if |
|||
string res = "" |
|||
integer k = 1, prev = 0 |
|||
while remainder(k*m,n) do |
|||
integer curr = floor(k*m/n) |
|||
res &= iff(prev=curr?"0":"10") |
|||
prev = curr |
|||
k += 1 |
|||
end while |
|||
return res |
|||
end function |
|||
function fibWord(integer n) |
|||
string Sn_1 = "0", |
|||
Sn = "01", |
|||
tmp = "" |
|||
for i=2 to n do |
|||
tmp = Sn |
|||
Sn &= Sn_1 |
|||
Sn_1 = tmp |
|||
end for |
|||
return Sn |
|||
end function |
|||
string fib = fibWord(7), |
|||
sturmian = sturmian_word(13, 21) |
|||
assert(fib[1..length(sturmian)] == sturmian) |
|||
?sturmian |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
"01001010010010100101001001010010" |
|||
</pre> |
|||
== {{header|Python}} == |
|||
For rational numbers:<syntaxhighlight lang="python3"> |
For rational numbers:<syntaxhighlight lang="python3"> |
||
def sturmian_word(m, n): |
def sturmian_word(m, n): |