Fibonacci sequence: Difference between revisions
Content added Content deleted
Space Ghost (talk | contribs) |
Space Ghost (talk | contribs) |
||
Line 7,035: | Line 7,035: | ||
=== Iterative === |
=== Iterative === |
||
<syntaxhighlight lang="haskell"> |
<syntaxhighlight lang="haskell"> |
||
import String from "string" |
|||
import File from "sys/file" |
import File from "sys/file" |
||
let fib = j => { |
let fib = j => { |
||
let mut fnow = 0, fnext = 1 |
let mut fnow = 0, fnext = 1 |
||
for (let mut n = 0; n <= j; n += 1) { |
for (let mut n = 0; n <= j; n += 1) { |
||
if (n == 0 || n == 1) { |
if (n == 0 || n == 1) { |
||
let output1 = |
let output1 = " " ++ toString(n) |
||
ignore(File.fdWrite(File.stdout, output1)) |
ignore(File.fdWrite(File.stdout, output1)) |
||
} else { |
} else { |
||
tempf = fnow + fnext |
let tempf = fnow + fnext |
||
fnow = fnext |
fnow = fnext |
||
fnext = tempf |
fnext = tempf |
||
let output2 = |
let output2 = " " ++ toString(fnext) |
||
ignore(File.fdWrite(File.stdout, output2)) |
ignore(File.fdWrite(File.stdout, output2)) |
||
} |
} |