Recaman's sequence: Difference between revisions
Content added Content deleted
(Easylang) |
Not a robot (talk | contribs) (Add SETL) |
||
Line 3,161: | Line 3,161: | ||
Terms of Recaman's sequence to generate all integers 0..1000, inclusive: 328003</pre> |
Terms of Recaman's sequence to generate all integers 0..1000, inclusive: 328003</pre> |
||
=={{header|SETL}}== |
|||
<syntaxhighlight lang="setl">program recaman; |
|||
a := {[0,0]}; |
|||
loop for i in [1..14] do |
|||
extend(a); |
|||
end loop; |
|||
print("First 15:", [a(n) : n in [0..14]]); |
|||
loop |
|||
doing n := extend(a); |
|||
until #(rept:=[[r,i] : r = a(i) | r=n]) > 1 |
|||
do pass; |
|||
end loop; |
|||
print("First repetition:", n, "at", {x:x in rept}{n}); |
|||
proc extend(rw a); |
|||
n := max/ domain a; |
|||
t := a(n) - n-1; |
|||
if t<0 or t in range a then |
|||
t := a(n) + n+1; |
|||
end if; |
|||
return a(n+1) := t; |
|||
end proc; |
|||
end program;</syntaxhighlight> |
|||
{{out}} |
|||
<pre>First 15: [0 1 3 6 2 7 13 20 12 21 11 22 10 23 9] |
|||
First repetition: 42 at {20 24}</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">func recamans_generator() { |
<syntaxhighlight lang="ruby">func recamans_generator() { |