Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created March 19, 2019 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marocchino/81b9d75708fdab6a312ba7e483e1df0a to your computer and use it in GitHub Desktop.
Save marocchino/81b9d75708fdab6a312ba7e483e1df0a to your computer and use it in GitHub Desktop.
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)
defmodule CostTest do
use ExUnit.Case
def cost([]), do: 0
def cost([_last]), do: 0
def cost([current | [next | tail]]) do
Enum.min([current + cost([next | tail]), next + cost(tail)])
end
test "1" do
assert cost([10, 15, 20]) == 15
end
test "2" do
assert cost([1, 100, 1, 1, 1, 100, 1, 1, 100, 1]) == 6
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment