Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
85
Task/Farey-sequence/PureBasic/farey-sequence.basic
Normal file
85
Task/Farey-sequence/PureBasic/farey-sequence.basic
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
EnableExplicit
|
||||
|
||||
Structure farey_struc
|
||||
complex.POINT
|
||||
quotient.d
|
||||
EndStructure
|
||||
|
||||
#MAXORDER=1000
|
||||
Global NewList fareylist.farey_struc()
|
||||
|
||||
Define v_start.i,
|
||||
v_end.i,
|
||||
v_step.i,
|
||||
order.i,
|
||||
fractions.i,
|
||||
check.b,
|
||||
t$
|
||||
|
||||
Procedure farey(order)
|
||||
NewList sequence.farey_struc()
|
||||
Define quotient.d,
|
||||
divisor.i,
|
||||
dividend.i
|
||||
|
||||
For divisor=1 To order
|
||||
For dividend=0 To divisor
|
||||
quotient.d=dividend/divisor
|
||||
AddElement(sequence())
|
||||
sequence()\complex\x=dividend
|
||||
sequence()\complex\y=divisor
|
||||
sequence()\quotient=quotient
|
||||
Next
|
||||
Next
|
||||
|
||||
SortStructuredList(sequence(),#PB_Sort_Ascending,
|
||||
OffsetOf(farey_struc\quotient),
|
||||
TypeOf(farey_struc\quotient))
|
||||
|
||||
FirstElement(sequence())
|
||||
quotient=sequence()\quotient
|
||||
AddElement(fareylist())
|
||||
fareylist()\complex\x=sequence()\complex\x
|
||||
fareylist()\complex\y=sequence()\complex\y
|
||||
fareylist()\quotient=sequence()\quotient
|
||||
|
||||
ForEach sequence()
|
||||
If quotient=sequence()\quotient : Continue : EndIf
|
||||
quotient=sequence()\quotient
|
||||
AddElement(fareylist())
|
||||
fareylist()\complex\x=sequence()\complex\x
|
||||
fareylist()\complex\y=sequence()\complex\y
|
||||
fareylist()\quotient=sequence()\quotient
|
||||
Next
|
||||
FreeList(sequence())
|
||||
EndProcedure
|
||||
|
||||
OpenConsole("Farey sequence [Input exit = program end]")
|
||||
Repeat
|
||||
Print("Input-> start end step [start>=1; end<=1000; step>=1; (start<end)] : ")
|
||||
t$=Input() : If Trim(LCase(t$))="exit" : End : EndIf
|
||||
v_start=Val(StringField(t$,1," "))
|
||||
v_end=Val(StringField(t$,2," "))
|
||||
v_step=Val(StringField(t$,3," "))
|
||||
check=Bool(v_start>=1 And v_end<=#MAXORDER And v_step>=1 And v_start<v_end)
|
||||
Until check=#True
|
||||
PrintN(~"\n"+LSet("-",80,"-"))
|
||||
|
||||
order=v_start
|
||||
While order<=v_end
|
||||
FreeList(fareylist()) : NewList fareylist()
|
||||
farey(order)
|
||||
fractions=ListSize(fareylist())
|
||||
PrintN("Farey sequence for order "+Str(order)+" has "+Str(fractions)+" fractions.")
|
||||
If fractions<100
|
||||
ForEach fareylist()
|
||||
If ListIndex(fareylist()) % 7 = 0 : PrintN("") : EndIf
|
||||
Print(~"\t"+
|
||||
RSet(Str(fareylist()\complex\x),2," ")+"/"+
|
||||
RSet(Str(fareylist()\complex\y),2," "))
|
||||
Next
|
||||
EndIf
|
||||
PrintN(~"\n"+LSet("=",80,"="))
|
||||
order+v_step
|
||||
Wend
|
||||
Input()
|
||||
Loading…
Add table
Add a link
Reference in a new issue