[Solved] Elixir Coin Change [closed]

try this defmodule MejorCambio do def darcambio(abono, adeudo) do td = abono – adeudo IO.inspect(“Tu cambio es de #{td}”) Enum.reduce([200,100,50,20,10, 5, 2, 1], %{abono: abono, adeudo: adeudo} , fn divisa, acc -> cambio = acc.abono – acc.adeudo repeat = div(cambio, divisa) acc2 = rem(cambio, divisa) %{deno: divisa , val: repeat} |> IO.inspect() %{acc | adeudo: … Read more

[Solved] Spanning repeatable keys

In Elixir it’s quite easy with Enum.group_by/3: iex> Enum.group_by(values, fn {key, _} -> key end, fn {_, value} -> value end) %{ “Caerus1” => [“Ramses Refiner”, “Jupiter Refiner”, “Jupiter Other”, “Trader 13”, “Cathode Supplier 4”], “Dionysus3” => [“Cathode Supplier 4”, “Ramses Refiner”, “Trader 13”, “Jupiter Refiner”, “Jupiter Other”], “Prometheus2” => [“Jupiter Other”, “Ramses Refiner”, “Trader … Read more

[Solved] Inserting and removing a character from a string

Adding characters “customer” <> “s” Removing characters Elixir idiomatic: String.trim_trailing(“users”, “s”) #⇒ “user” More efficient for long strings: with [_ | tail] <- “users” |> to_charlist |> :lists.reverse, do: tail |> :lists.reverse |> to_string Most efficient (credits to @Dogbert): str = “users” sz = :erlang.byte_size(str), :erlang.binary_part(str, {0, sz – 1}) 6 solved Inserting and removing a … Read more