Last active
December 15, 2015 04:26
-
-
Save octosteve/29be748361e84e3b25bd to your computer and use it in GitHub Desktop.
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 Paralindrome do | |
def are_palindromes?(list) do | |
parent_process = self | |
Enum.map(list, fn (word) -> | |
spawn(fn -> | |
send parent_process, {self, word, is_palindrome?(word) } | |
end) | |
end) | |
|> Enum.each fn (process_id) -> | |
receive do | |
{^process_id, word, status} -> | |
IO.puts "#{word} is a Palindrome: #{status}" | |
end | |
end | |
end | |
def is_palindrome?(word) do | |
word == String.reverse(word) | |
end | |
end | |
Paralindrome.are_palindromes?(["mom", "hat"]) |
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 Paralindrome do | |
def are_palindromes?(list) do | |
Enum.map(list, fn (word) -> | |
Task.async(fn -> {word, is_palindrome?(word) } end) | |
end) | |
|> Enum.each fn (task) -> | |
case Task.await(task) do | |
{word, true} -> | |
IO.puts "#{word} is a Palindrome" | |
_ -> nil | |
end | |
end | |
end | |
def is_palindrome?(word) do | |
word == String.reverse(word) | |
end | |
end | |
list = File.read!("/usr/share/dict/words") |> String.split("\n") | |
Paralindrome.are_palindromes?(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment