Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
fixup: Swift example takes arguments from CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Zak <[email protected]>
  • Loading branch information
rjzak committed Jul 28, 2022
1 parent 78f72e8 commit 2d5606a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions Swift/fibonacci/fibonacci.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
func fibonacci(n: Int) -> Int {
var a = 0
var b = 1
for _ in 0..<n {
let temp = a
a = b
b = temp + b
func FibonacciSequence(n: Int) -> Int {
var a = 0
var b = 1
for _ in 0..<n {
let temp = a
a = b
b = temp + b
}
return a
}
return a

var n = 10

let arguments = CommandLine.arguments

if (arguments.count > 1) {
n = Int(arguments[1]) ?? 10
if (n > 45) {
n = 45
}
}

print(fibonacci(n:7))

print("Fibonacci sequence number at index \(n) is \(FibonacciSequence(n: n))")

0 comments on commit 2d5606a

Please sign in to comment.