Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
28
Task/Calkin-Wilf-sequence/Uiua/calkin-wilf-sequence.uiua
Normal file
28
Task/Calkin-Wilf-sequence/Uiua/calkin-wilf-sequence.uiua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Generate Calkin-Wilf sequence, then use continued fractions
|
||||
# to discover position in the sequence of any given a/b.
|
||||
|
||||
Gcd ← ⊙◌⍢(⟜◿:|±,)°⊟
|
||||
Reduce ← ÷⊸Gcd # Reduce a rational [a b] to its normal form.
|
||||
Add ← Reduce ⊟⊓/+(⊢⇌)∩×⇌,, # Add pair of rationals [a b] [c d]
|
||||
Subtract ← Add ⊙⍜⊢¯ # Difference of pair of rationals [a b] [c d]
|
||||
Multiply ← Reduce × # Multiply pair of rationals [a b] [c d]
|
||||
Divide ← Multiply ⊙⇌
|
||||
Floor ← Reduce ⊟:1⌊/÷⇌
|
||||
|
||||
CwNext ← ⇌Subtract:⟜(Add1_1Multiply2_1Floor)
|
||||
&p"First twenty terms of Calkin-Wilf sequence:"
|
||||
&p/◇⊂≡(□$"_/_ "°⊟)⇌[⍥(CwNext.)20 [1 1]]
|
||||
|
||||
Cf ← ⇌Subtract⟜(.⊟:1⌊÷:°⊟)
|
||||
|
||||
ContFracRat ← ⇌≡⊢↘1[⍢(Cf|≠0⊡1)] # Continued Fraction for rational [a b].
|
||||
OddContFrac ← ⍥(⊂:1⍜(↙¯1|-1))¬◿2⧻.ContFracRat # Force length to be odd.
|
||||
CwPos ← °⋯⇌∧(⊂↯°⊟)⍉⊟⟜(¬◿2⇡⧻):[] OddContFrac # Calculate pos as described.
|
||||
&p""
|
||||
{[9 4] [83116 51639]}
|
||||
≡◇(&p $"_/_ is at position _ in the sequence"°⊟⟜CwPos)
|
||||
&p""
|
||||
# And show that the relation works in reverse
|
||||
ContFracInt ← ⍥(⊂0)=0⊢⟜(⊜⧻.+1)⋯
|
||||
CwAt ← /(Add⇌)≡(⇌⊟1)⇌ContFracInt
|
||||
&p$"The number at position _ is _/_"⟜(°⊟CwAt)123456789
|
||||
Loading…
Add table
Add a link
Reference in a new issue