diff --git a/.gitignore b/.gitignore index 0a016c7..ace1bc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ Rust/*/target/ +Nim/*/* +!Nim/*/*.* +!Nim/*/*/ Zig/*/zig-cache/ Zig/*/zig-out/ .idea/ diff --git a/Nim/README.md b/Nim/README.md new file mode 100644 index 0000000..0ae4564 --- /dev/null +++ b/Nim/README.md @@ -0,0 +1,18 @@ +# Nim Examples + + + +todo + + + + + +For setting up your environment and installing the necessary tools, see [the Enarx documentation on using WebAssembly with Nim](https://enarx.dev/docs/WebAssembly/Nim). + +nim c -r -d:release fibonacci.nim + +or + +nimble run +nimble run -- 10 diff --git a/Nim/fibonacci/fibonacci.nimble b/Nim/fibonacci/fibonacci.nimble new file mode 100644 index 0000000..2ec0334 --- /dev/null +++ b/Nim/fibonacci/fibonacci.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "Profian" +description = "Fibonacci example." +license = "Apache-2.0" +srcDir = "src" +bin = @["fibonacci"] + + +# Dependencies + +requires "nim >= 1.6.6" diff --git a/Nim/fibonacci/src/fibonacci.nim b/Nim/fibonacci/src/fibonacci.nim new file mode 100644 index 0000000..6435770 --- /dev/null +++ b/Nim/fibonacci/src/fibonacci.nim @@ -0,0 +1,32 @@ +import std/os, std/parseutils, std/rdstdin, std/strformat + +proc fib(n: int): int = + case n: + of 0, 1: + n + else: + fib(n - 1) + fib(n - 2) + +proc main = + var args = commandLineParams() + + if args.len == 0: + var line: string + + if not readLineFromStdin("Enter a non-negative number: ", line): + echo ("Failed to read line") + quit QuitFailure + + args.add(line) + + var index: int + + for arg in args: + if arg.parseInt(index) == 0: + echo fmt("Failed to parse number: {arg}") + quit QuitFailure + + echo (fmt"Fibonacci sequence number at index {index} is {fib(index)}") + +when isMainModule: + main()