4 ms·
It gave me this: defmodule Fibonnaci do def fibonnaci(0), do: 0 def fibonnaci(1), do: 1 def fibonnaci(n), do: fibonnaci(n - 1) + fibonnaci(n - 2)
by Filligree 4y ago
It gave me this:
defmodule Fibonnaci do
def fibonnaci(0), do: 0
def fibonnaci(1), do: 1
def fibonnaci(n), do: fibonnaci(n - 1) + fibonnaci(n - 2)
end
Which seems fine I guess (I don't know the language), but doesn't even have comments. I prefer my files with comments. After forcing the point, I got this:
defmodule Fibonnaci do
@moduledoc """
Documentation for Fibonnaci.
"""
@doc """
Calculates the nth Fibonnaci number
"""
def fibonnaci(n) when n < 0, do: nil
def fibonnaci(0), do: 0
def fibonnaci(1), do: 1
def fibonnaci(n), do: fibonnaci(n - 1) + fibonnaci(n - 2)
end
In which I prompted the AI with everything up to (and including) @doc. So I figure it was picking it up from your computer, somehow.
EDIT: I then noticed the typo, tried it with fibonacci.ex, and got the same result.
- zelphirkalt 4y agoInteresting though, that it is bad code, considering, that it is not written to be tail recursive. Maybe good to show the idea of fibonnaci numbers or a theoretically valid implementation. But hopefully people do not accept this kind of code, thinking, that because it gets the result in some simple cases and it was suggested by copilot, it must be the way to properly do things.