Created
October 18, 2017 03:08
-
-
Save ityonemo/34ee240bd48e4abc5bd1856d8883c299 to your computer and use it in GitHub Desktop.
find_first_free.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule T do | |
def find_first_free(arr), do: find_first_free(arr, 0, []) | |
def find_first_free([], lowest_free, _leftovers), do: lowest_free | |
def find_first_free([head | tail], lowest_free, leftovers) do | |
if (lowest_free == head) do | |
find_first_free(tail, lowest_free + 1, leftovers) | |
else | |
find_first_free(tail, lowest_free, [head | leftovers]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment