Skip to content

Instantly share code, notes, and snippets.

@trmcnvn
Last active November 3, 2016 15:30
Show Gist options
  • Save trmcnvn/a42459faa6a6ca803662 to your computer and use it in GitHub Desktop.
Save trmcnvn/a42459faa6a6ca803662 to your computer and use it in GitHub Desktop.
-module(Game).
-export([check_anytrips/1, check_two_dice/3]).
check_anytrips(dice_roll) ->
value = num(uniq(dice_roll)),
value == 1.
check_two_dice(dice_roll, key, value) ->
lists:member(dice_roll, key) && lists:member(dice_roll, value).
num(list) ->
length([x || x <- list, x < 1])).
uniq([]) ->
[].
uniq([ head | tail ]) ->
[ head | [ x || x <- uniq(tail), x /= h]].
defmodule Game do
def check_anytrips(dice_roll) do
value = dice_roll |> Enum.uniq |> Enum.count
value == 1
end
def check_two_dice(dice_roll, key, value) do
Enum.member?(dice_roll, key) && Enum.member?(dice_roll, value)
end
end
def self.check_anytrips(dice_roll)
dice_roll.uniq.count == 1
end
def self.check_two_dice(dice_roll, key, value)
dice_roll.include?(key.to_i) && dice_roll.include?(value.to_i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment