RosettaCodeData/Task/Greedy-algorithm-for-Egyptian-fractions/Microsoft-Small-Basic/greedy-algorithm-for-egyptian-fractions.basic
2023-07-01 13:44:08 -04:00

54 lines
757 B
Text

'Egyptian fractions - 26/07/2018
xx=2014
yy=59
x=xx
y=yy
If x>=y Then
q=Math.Floor(x/y)
tt="+("+q+")"
x=Math.Remainder(x,y)
EndIf
If x<>0 Then
While x<>1
'i=modulo(-y,x)
u=-y
v=x
modulo()
i=ret
k=Math.Ceiling(y/x)
m=m+1
tt=tt+"+1/"+k
j=y*k
If i=1 Then
tt=tt+"+1/"+j
EndIf
'n=gcd(i,j)
x=i
y=j
gcd()
n=ret
x=i/n
y=j/n
EndWhile
EndIf
TextWindow.WriteLine(xx+"/"+yy+"="+Text.GetSubTextToEnd(tt,2))
Sub modulo
wr=Math.Remainder(u,v)
While wr<0
wr=wr+v
EndWhile
ret=wr
EndSub
Sub gcd
wx=i
wy=j
wr=1
While wr<>0
wr=Math.Remainder(wx,wy)
wx=wy
wy=wr
EndWhile
ret=wx
EndSub