Thanks to both of you. The combination of your solution looks great!
defmodule CheckExam do def check_exam(correct, answer, score \\ 0) def check_exam([right | correct], [right | answer], score), do: check_exam(correct, answer, score + 4) def check_exam([_right | correct], ["" | answer], score), do: check_exam(correct, answer, score) def check_exam([_right | correct], [_wrong| answer], score), do: check_exam(correct, answer, score - 1) def check_exam([], [], score) when score < 0, do: 0 def check_exam([], [], score), do: score end CheckExam.check_exam(["a", "a", "b", "b"], ["a", "c", "b", "d"]) CheckExam.check_exam(["a", "a", "c", "b"], ["a", "a", "b", ""]) CheckExam.check_exam(["a", "a", "b", "c"], ["a", "a", "b", "c"]) CheckExam.check_exam(["b", "c", "b", "a"], ["", "a", "a", "c"])
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks to both of you. The combination of your solution looks great!