1. rgrau
  2. language-learning-apps

Commits

rgrau  committed 096590d

guess number

  • Participants
  • Parent commits 2d51f12
  • Branches master

Comments (0)

Files changed (1)

File elixir/guess.exs

View file
+defmodule Guess do
+  def guess(actual // :random.uniform) do
+    IO.puts("Choose number:")
+    {result , rest } = String.to_integer(String.rstrip(IO.readline()))
+    say_what(result , actual)
+  end
+
+  def say_what(try, actual) when actual < try do
+    IO.puts "actual => #{actual}, try => #{try}"
+    IO.puts "too big"
+    guess(actual)
+  end
+  def say_what(try, actual) when actual > try do
+    IO.puts "too small"
+    guess(actual)
+  end
+
+  def say_what(try, actual), do: IO.puts("YEAH!")
+
+  def start(range) do
+    from..to = range
+    :random.seed(:erlang.now)
+    guess(:random.uniform(to - from) + from )
+  end
+end
+
+
+Guess.start(1..100)