Compare commits
3 Commits
29c5e28034
...
ba73d0040f
Author | SHA1 | Date |
---|---|---|
Nathan Mattes | ba73d0040f | |
Nathan Mattes | 193d58827f | |
Nathan Mattes | ff8cd2798a |
|
@ -0,0 +1,33 @@
|
|||
defmodule StringsAndBinaries do
|
||||
def ascii_printable?(char_list) do
|
||||
List.ascii_printable?(char_list)
|
||||
end
|
||||
|
||||
def custom_ascii_printable?(char_list) do
|
||||
# every character in char list must between 32 and 126
|
||||
Enum.all?(char_list, &( 32 <= &1 and &1 <= 126))
|
||||
end
|
||||
|
||||
def anagram?(word1, word2) do
|
||||
# An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
|
||||
Enum.sort(String.to_charlist(word1)) == Enum.sort(String.to_charlist(word2))
|
||||
end
|
||||
|
||||
def calculate(expression) do
|
||||
# this might be a bit dirty, but it solves the issue.
|
||||
[a, operator, b] = ~w[ #{expression} ]
|
||||
a = String.to_integer(a)
|
||||
b = String.to_integer(b)
|
||||
case operator do
|
||||
"+" -> add(a, b)
|
||||
"-" -> substract(a, b)
|
||||
"*" -> multiply(a, b)
|
||||
"/" -> divide(a, b)
|
||||
end
|
||||
end
|
||||
|
||||
defp add(a, b), do: a + b
|
||||
defp substract(a, b), do: a - b
|
||||
defp multiply(a, b), do: a * b
|
||||
defp divide(a, b), do: a / b
|
||||
end
|
Loading…
Reference in New Issue