diff --git a/09_dynamic_programming/elixir/01_longest_common_subsequence.exs b/09_dynamic_programming/elixir/01_longest_common_subsequence.exs new file mode 100644 index 0000000..c9bcb66 --- /dev/null +++ b/09_dynamic_programming/elixir/01_longest_common_subsequence.exs @@ -0,0 +1,12 @@ +# `cell` is a map of maps here, e.g. +# cell = %{ +# 0 => %{0 => 0, ...}, +# 1 => %{...}, +# ... +# } + +if String.at(word_a, i) == String.at(word_a, j) do + put_in(cell[i - 1][j - 1], cell[i - 1][j - 1] + 1) +else + put_in(cell[i - 1][j - 1], max(cell[i - 1][j], cell[i][j - 1])) +end