Commits

rgrau committed 2d51f12

elixir factorial and hanoi

Comments (0)

Files changed (2)

+defmodule Fact do
+  def factorial(0), do: 0
+  def factorial(1), do: 1
+  def factorial(n) when n > 0 do
+    n * factorial(n - 1)
+  end
+end
+IO.puts(Fact.factorial(10))
+defmodule Hanoi do
+  def hanoi(from,to,aux, 1), do: move(from, to)
+  def hanoi(from,to,aux, n) do
+    hanoi(from, aux, to, n - 1)
+    move(from, to)
+    hanoi(aux, to, from, n - 1)
+  end
+
+  def move(from, to) do
+      IO.puts("move from #{from} to #{to}")
+  end
+end
+
+Hanoi.hanoi(1,3,2 , 3)