Skip to content

Instantly share code, notes, and snippets.

@navneetgupta
Last active September 8, 2018 14:26
Show Gist options
  • Select an option

  • Save navneetgupta/70cc53e8a77aeb31b36db28904fc81a7 to your computer and use it in GitHub Desktop.

Select an option

Save navneetgupta/70cc53e8a77aeb31b36db28904fc81a7 to your computer and use it in GitHub Desktop.

Revisions

  1. navneetgupta revised this gist Sep 8, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions fibonacci.ex
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```
    defmodule FibonacciCalc do

    def fibonacci(x) when x <= 0, do: IO.puts "Enter a number greater than 0"
    @@ -12,5 +11,4 @@ defmodule FibonacciCalc do
    IO.puts "#{first}"
    calculate_fibonacci(x-1,second, first+second)
    end
    end
    ````
    end
  2. navneetgupta created this gist Sep 8, 2018.
    16 changes: 16 additions & 0 deletions fibonacci.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    ```
    defmodule FibonacciCalc do

    def fibonacci(x) when x <= 0, do: IO.puts "Enter a number greater than 0"

    def fibonacci(x) do
    calculate_fibonacci(x,1,1)
    end

    def calculate_fibonacci(x, first, _second ) when x == 1, do: IO.puts "#{first}"
    def calculate_fibonacci(x, first, second ) do
    IO.puts "#{first}"
    calculate_fibonacci(x-1,second, first+second)
    end
    end
    ````