Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,44 @@
|
|||
' Recaman's sequence - smallbasic - 05/08/2015
|
||||
nn=15
|
||||
TextWindow.WriteLine("Recaman's sequence for the first " + nn + " numbers:")
|
||||
recaman()
|
||||
TextWindow.WriteLine(Text.GetSubTextToEnd(recaman,2))
|
||||
nn="firstdup"
|
||||
recaman()
|
||||
TextWindow.WriteLine("The first duplicated term is a["+n+"]="+a[n])
|
||||
|
||||
Sub recaman
|
||||
a=""
|
||||
b=""
|
||||
dup=""
|
||||
recaman=""
|
||||
firstdup=""
|
||||
If nn="firstdup" Then
|
||||
nn=1000
|
||||
firstdup="True"
|
||||
EndIf
|
||||
For n=0 To nn-1
|
||||
ap=a[n-1]+n
|
||||
If a[n-1]<=n Then
|
||||
a[n]=ap 'a[n]=a[n-1]+n
|
||||
b[ap]=1
|
||||
Else
|
||||
am=a[n-1]-n
|
||||
If b[am]=1 Then
|
||||
a[n]=ap 'a[n]=a[n-1]+n
|
||||
b[ap]=1
|
||||
Else
|
||||
a[n]=am 'a[n]=a[n-1]-n
|
||||
b[am]=1
|
||||
EndIf
|
||||
EndIf
|
||||
If firstdup Then
|
||||
If dup[a[n]]=1 Then
|
||||
Goto exitsub
|
||||
EndIf
|
||||
dup[a[n]]=1
|
||||
EndIf
|
||||
recaman=recaman+","+a[n]
|
||||
EndFor
|
||||
exitsub:
|
||||
EndSub
|
||||
Loading…
Add table
Add a link
Reference in a new issue