Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Recamans-sequence/Comal/recamans-sequence.comal
Normal file
26
Task/Recamans-sequence/Comal/recamans-sequence.comal
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
0010 DIM a#(0:100)
|
||||
0020 //
|
||||
0030 // Print the first 15 items
|
||||
0040 PRINT "First 15 items: ",
|
||||
0050 FOR i#:=0 TO 14 DO PRINT reca#(i#);
|
||||
0060 PRINT
|
||||
0070 //
|
||||
0080 // Find and print the first repeated item
|
||||
0090 i#:=15
|
||||
0100 WHILE NOT find#(i#,reca#(i#)) DO i#:+1
|
||||
0110 PRINT "First repeated item: A(",i#,") = ",a#(i#)
|
||||
0120 //
|
||||
0130 // Generate the n'th member of the Recaman sequence
|
||||
0140 FUNC reca#(n#)
|
||||
0150 IF n#=0 THEN RETURN 0
|
||||
0160 a#(n#):=a#(n#-1)-n#
|
||||
0180 IF a#(n#)<=0 OR find#(n#,a#(n#)) THEN a#(n#):=a#(n#-1)+n#
|
||||
0190 RETURN a#(n#)
|
||||
0200 ENDFUNC reca#
|
||||
0210 //
|
||||
0220 // See if a number occurs before the n'th member of the Recaman sequence
|
||||
0230 FUNC find#(n#,num#)
|
||||
0240 FOR x#:=0 TO n#-1 DO IF a#(x#)=num# THEN RETURN x#
|
||||
0250 RETURN 0
|
||||
0260 ENDFUNC find#
|
||||
0270 END
|
||||
Loading…
Add table
Add a link
Reference in a new issue