Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Recamans-sequence/Sidef/recamans-sequence.sidef
Normal file
46
Task/Recamans-sequence/Sidef/recamans-sequence.sidef
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
func recamans_generator() {
|
||||
|
||||
var term = 0
|
||||
var prev = 0
|
||||
var seen = Hash()
|
||||
|
||||
{
|
||||
var this = (prev - term)
|
||||
|
||||
if ((this <= 0) || seen{this}) {
|
||||
this = (prev + term)
|
||||
}
|
||||
|
||||
prev = this
|
||||
seen{this} = true
|
||||
term++
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
with (recamans_generator()) { |r|
|
||||
say ("First 15 terms of the Recaman's sequence: ", 15.of { r.run }.join(', '))
|
||||
}
|
||||
|
||||
with (recamans_generator()) {|r|
|
||||
var seen = Hash()
|
||||
Inf.times {|i|
|
||||
var n = r.run
|
||||
if (seen{n}) {
|
||||
say "First duplicate term in the series is a(#{i}) = #{n}"
|
||||
break
|
||||
}
|
||||
seen{n} = true
|
||||
}
|
||||
}
|
||||
|
||||
with (recamans_generator()) {|r|
|
||||
var seen = Hash()
|
||||
Inf.times {|i|
|
||||
var n = r.run
|
||||
if ((n <= 1000) && (seen{n} := true) && (seen.len == 1001)) {
|
||||
say "Terms up to a(#{i}) are needed to generate 0 to 1000"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue