Last active
August 29, 2015 14:14
-
-
Save foliveira/b79e12481ab50ae90941 to your computer and use it in GitHub Desktop.
Fun with Elixir
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 Fun do | |
def max([x]), do: x | |
def max([ head | tail ]), do: Kernel.max(head, max(tail)) | |
end |
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 Fun do | |
def slice(x, start, length), do: x | |
end |
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 Fun do | |
def swap([head | tail], _, 1, carry, rest), do: [head] ++ List.delete_at(rest, -1) ++ [carry] ++ tail | |
def swap([head | tail], 1, second, carry, rest), do: swap(tail, 1, second - 1, carry, rest ++ [hd(tail)]) | |
def swap([head | tail], first, second, _, rest), do: [head] ++ swap(tail, first - 1, second - 1, hd(tail), rest) | |
def swap(x, first, second), do: swap(x, first, second, hd(x), []) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment