Created
September 20, 2017 00:20
-
-
Save brandonpittman/301bdf5c5f84dfe517a2bdf72fb1907c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Lists do | |
def len([]), do: 0 | |
def len([ _head | tail ]), do: 1 + len(tail) | |
def sum([]), do: 0 | |
def sum([h | t]), do: h + sum(t) | |
def double([]), do: [] | |
def double([head | tail ]), do: [2*head | double(tail)] | |
def square([]), do: [] | |
def square([head | tail ]), do: [head*head | square(tail)] | |
def sum_pairs([]), do: [] | |
def sum_pairs([ h1, h2 | t]), do: [ h1 + h2 | sum_pairs(t) ] | |
def even_length?([]), do: true | |
def even_length?([ _, _ | [_]]), do: false | |
def even_length?([ _, _ | _]), do: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment