Last active
November 3, 2016 15:30
-
-
Save trmcnvn/a42459faa6a6ca803662 to your computer and use it in GitHub Desktop.
This file contains 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
-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]]. |
This file contains 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 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 |
This file contains 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
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