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
def product_of_equals_twenty_twenty(_list, product) when product != nil, do: product |
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
defp get_two([first | [second | _rest]]) | |
when equals_twenty_twenty(first, second) do | |
first * second | |
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 Accountant do | |
@sum 2020 | |
defguard equals_twenty_twenty(first, second) when first + second == @sum | |
# ... |
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
defp get_two(list) when length(list) == 1, do: nil |
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
def product_of_equals_twenty_twenty([_head | tail] = list, _product) do | |
product_of_equals_twenty_twenty(tail, get_two(list)) | |
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
def product_of_equals_twenty_twenty([_head | tail] = list, _product) do | |
product_of_equals_twenty_twenty(tail, get_two(list)) | |
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
def product_of_equals_twenty_twenty(_list, product) when product != nil, do: product |
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
def product_of_equals_twenty_twenty([_head | tail] = list, _product) do | |
product_of_equals_twenty_twenty(tail, get_two(list)) | |
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
Accountant.product_of_equals_twenty_twenty([979, 1721, 366, 299, 675, 1456]) |
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
defp get_two(list) when length(list) == 1, do: nil |
NewerOlder