Data update
This commit is contained in:
parent
07c7092a52
commit
61b93a2cd1
313 changed files with 6160 additions and 346 deletions
28
Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua
Normal file
28
Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
function hofstadter (limit)
|
||||
local Q = {1, 1}
|
||||
for n = 3, limit do
|
||||
Q[n] = Q[n - Q[n - 1]] + Q[n - Q[n - 2]]
|
||||
end
|
||||
return Q
|
||||
end
|
||||
|
||||
function countDescents (t)
|
||||
local count = 0
|
||||
for i = 2, #t do
|
||||
if t[i] < t[i - 1] then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
local noError, hofSeq = pcall(hofstadter, 1e5)
|
||||
if noError == false then
|
||||
print("The sequence could not be calculated up to the specified limit.")
|
||||
os.exit()
|
||||
end
|
||||
for i = 1, 10 do
|
||||
io.write(hofSeq[i] .. " ")
|
||||
end
|
||||
print("\n" .. hofSeq[1000])
|
||||
print(countDescents(hofSeq))
|
||||
Loading…
Add table
Add a link
Reference in a new issue