aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-285/wambash/elixir/ch-2.exs30
-rw-r--r--challenge-285/wambash/raku/ch-1.raku19
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-285/wambash/elixir/ch-2.exs b/challenge-285/wambash/elixir/ch-2.exs
new file mode 100644
index 0000000000..499304306b
--- /dev/null
+++ b/challenge-285/wambash/elixir/ch-2.exs
@@ -0,0 +1,30 @@
+defmodule Change do
+ defp _making({0,_}),do: [1]
+ defp _making({_,[]}),do: [0]
+ defp _making({amount, [hc| coins]}) when hc > amount, do: _making({amount,coins})
+ defp _making({amount, coins}) do
+ coins
+ |> Enum.flat_map(fn
+ x -> _making(
+ {
+ amount - x,
+ coins |> Enum.drop_while( & &1 > x )
+ }
+ )
+ end)
+ end
+ def making(w) do
+ _making(w) |> Enum.sum
+ end
+end
+
+ExUnit.start()
+
+defmodule ChangeTest do
+ use ExUnit.Case
+ test "Change" do
+ assert Change.making({9,[50,25,10,5,1]}) == 2
+ assert Change.making({100,[50,25,10,5,1]}) == 292
+ assert Change.making({15,[50,25,10,5,1]}) == 6
+ end
+end
diff --git a/challenge-285/wambash/raku/ch-1.raku b/challenge-285/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..dc74e10a33
--- /dev/null
+++ b/challenge-285/wambash/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+
+multi no_connection (+@ ($from, $to)) { $to }
+multi no_connection (+@routes) {
+ my :(@from, @to) := [Z] @routes;
+
+ @to.first: { $_ ∉ @from }
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is no_connection(<B C>, <D B>, <C A>), 'A';
+ is no_connection(<A Z>), 'Z';
+ done-testing;
+}
+
+multi MAIN (+@routes) {
+ say no_connection +@routes
+}