- Commit
- 145ef3b83b6887e610b12efbf01f88e854e024d1
- Parent
- 17209f51d5e5f856de15c37c897253377ff3d5ae
- Author
- Pablo Escobar Gaviria <gark.garcia@protonmail.com>
- Date
Fixed ambiguous parentheses in Elixir implementation.
An exercise on polyglossy: the same problem solved on multiple languages
Fixed ambiguous parentheses in Elixir implementation.
2 files changed, 11 insertions, 17 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | Elixir/digital_sum.ex | 26 | 11 | 15 |
Modified | x86/PROGRAM.ASM | 2 | 0 | 2 |
diff --git a/Elixir/digital_sum.ex b/Elixir/digital_sum.ex @@ -3,17 +3,17 @@ defmodule Conjecture do case System.argv() |> Enum.map(fn s -> Integer.parse s end) do [{max, ""}, {n_processes, ""}] -> run max, n_processes [{max, ""}] -> run max, 1 - _ -> invalid_input() + _ -> :invalid_input end end def run max, n_processes do if max < 0 or n_processes <= 0 do - invalid_input() + :invalid_input else # Spawn a new process for each starting index from 0 to ``max` - f = fn i -> spawn fn -> counterexpl i, max, n_processes end end - pids = Enum.map 0..max, f + f = fn i -> spawn fn -> get_counterexpl i, max, n_processes end end + pids = Enum.map 1..n_processes, f # Send the current PID to each process Enum.map pids, fn pid -> send pid, self() end @@ -26,27 +26,27 @@ defmodule Conjecture do def listen n do receive do - :found -> System.halt 1 :ok -> listen (n - 1) + msg -> msg end end - def counterexpl start, max, n_processes do + def get_counterexpl start, max, n_processes do receive do parent_pid -> - if counterexpl_loop start, max, n_processes do - send parent_pid, :found + if counterexpl start, max, n_processes do + send parent_pid, :fail else send parent_pid, :ok end end end - def counterexpl_loop a, max, n_processes do + def counterexpl a, max, n_processes do cond do iter a, 0 -> true a + n_processes <= max -> - counterexpl_loop (a + n_processes), max, n_processes + counterexpl (a + n_processes), max, n_processes true -> false end end @@ -60,7 +60,7 @@ defmodule Conjecture do end def test a, b do - rem (sum (a + b) - sum a - sum b), 9 == 0 + 0 != rem(sum(a + b) - sum(a) - sum(b), 9) end def sum 0 do 0 end @@ -71,8 +71,4 @@ defmodule Conjecture do d + sum r end - - def invalid_input do - System.halt 2 - end end
diff --git a/x86/PROGRAM.ASM b/x86/PROGRAM.ASM @@ -119,8 +119,6 @@ invalid_input: mov ah, 2h ; Print '\'' - ;mov dx, 0ah - ;int 21 mov dx, 27h int 21