Created
November 23, 2016 14:41
-
-
Save kana-sama/6821f836a99ca74a4923379638492eb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule World do | |
defp prev_height(p1, p2) do | |
cond do | |
p1 == 0 -> p2 | |
p2 == 0 -> p1 | |
true -> if Dice.success?(0.7), do: p1, else: p2 | |
end | |
end | |
def inc([]) do | |
[10, 10, 10, 10, 10] | |
end | |
def inc([p1, p2 | _] = cols) do | |
prev = prev_height p1, p2 | |
cur = if Dice.success? 0.7 do | |
prev + Dice.roll 2 | |
else | |
if Dice.success? 0.8 do | |
prev - Dice.roll 2 | |
else | |
prev - Dice.roll prev | |
end | |
end | |
cur = Enum.max([cur, 0]) | |
cur = Enum.min([cur, 20]) | |
[cur | cols] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment