Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Recamans-sequence/Wren/recamans-sequence.wren
Normal file
24
Task/Recamans-sequence/Wren/recamans-sequence.wren
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var a = [0]
|
||||
var used = { 0: true }
|
||||
var used1000 = { 0: true }
|
||||
var foundDup = false
|
||||
var n = 1
|
||||
while (n <= 15 || !foundDup || used1000.count < 1001) {
|
||||
var next = a[n-1] - n
|
||||
if (next < 1 || used[next]) next = next + 2*n
|
||||
var alreadyUsed = used[next]
|
||||
a.add(next)
|
||||
if (!alreadyUsed) {
|
||||
used[next] = true
|
||||
if (next >= 0 && next <= 1000) used1000[next] = true
|
||||
}
|
||||
if (n == 14) System.print("The first 15 terms of the Recaman's sequence are:\n%(a)")
|
||||
if (!foundDup && alreadyUsed) {
|
||||
System.print("The first duplicated term is a[%(n)] = %(next)")
|
||||
foundDup = true
|
||||
}
|
||||
if (used1000.count == 1001) {
|
||||
System.print("Terms up to a[%(n)] are needed to generate 0 to 1000")
|
||||
}
|
||||
n = n + 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue