Skip to content

Some changes for workshop exercises #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Workshop.Exercise.DeterminePair do
# given `@task`.
@description """
Complete the function determine_pair, which will return a boolean, determining
if the hand of 5 cards does include a pair (two cards of samen number).
if the hand of 5 cards does include a pair (two cards of same number).

# What's next?
Get the task for this exercise by executing `mix workshop.task`. When you are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ defmodule Pair do

# One pair
@spec determine_pair(list) :: boolean
def determine_pair([[_, a], [_, a], _, _, _]), do: true
def determine_pair([_, [_, a], [_, a], _, _]), do: true
def determine_pair([_, _, [_, a], [_, a], _]), do: true
def determine_pair([_, _, _, [_, a], [_, a]]), do: true

def determine_pair(_), do: false
def determine_pair(list) do
new_list = Enum.uniq_by(list, fn [_, x] -> x end)
cond do
length(new_list) < 5 ->
true
true ->
false
end
end
end
43 changes: 25 additions & 18 deletions studygroup_001/.workshop/exercises/determine_pair/test/check.exs
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
defmodule Workshop.Exercise.DeterminePairCheck do
use Workshop.Validator
use ExUnit.Case
import Pair

test "one pair" do
assert(determine_pair(one_pair))
verify "one pair" do
(Pair.determine_pair(one_pair) == true && :ok) || {:error, "One Pair failed to validate"}
end

test "straight has no pair" do
refute(determine_pair(straight))
verify "one pair separated should be valid" do
(Pair.determine_pair(one_pair_separated) == true && :ok) || {:error, "One Pair failed to validate"}
end

test "two pairs has a pair" do
assert(determine_pair(two_pairs))
verify "straight has no pair" do
(Pair.determine_pair(straight) != true && :ok) || {:error, "One Pair failed to validate"}
end

test "full house has no pair" do
assert(determine_pair(full_house))
verify "two pairs has a pair" do
(Pair.determine_pair(two_pairs) == true && :ok) || {:error, "One Pair failed to validate"}
end

test "something has no pair" do
refute(determine_pair(something))
verify "full house has a pair" do
(Pair.determine_pair(full_house) == true && :ok) || {:error, "One Pair failed to validate"}
end

test "four of kind has a pair" do
assert(determine_pair(four_of_kind))
verify "something has no pair" do
(Pair.determine_pair(something) != true && :ok) || {:error, "One Pair failed to validate"}
end

test "three of kind has a pair" do
assert(determine_pair(three_of_kind))
verify "four of kind has a pair" do
(Pair.determine_pair(four_of_kind) == true && :ok) || {:error, "One Pair failed to validate"}
end

verify "three of kind has a pair" do
(Pair.determine_pair(three_of_kind) == true && :ok) || {:error, "One Pair failed to validate"}
end

defp four_of_kind do
Expand All @@ -55,11 +58,15 @@ defmodule Workshop.Exercise.DeterminePairCheck do
[ [:hearts, 5], [:spades, 5], [:diamonds, 6], [:clubs, :ace], [:hearts, 7] ]
end

defp one_pair_separated do
[ [:hearts, 5], [:hearts, 7], [:diamonds, 6], [:clubs, :ace], [:spades, 5] ]
end

defp something do
[ [:hearts, 5], [:spades, 4], [:diamonds, 6], [:clubs, :jack], [:hearts, 7] ]
end

# verify "all tests pass" do
# ((%{failures: 0} = ExUnit.run) && :ok) || ExUnit.start && {:error, "Some tests have failed"}
# end
# verify "all tests pass" do
# ((%{failures: 0} = ExUnit.run) && :ok) || ExUnit.start && {:error, "Some tests have failed"}
# end
end
12 changes: 6 additions & 6 deletions studygroup_001/.workshop/exercises/first_exercise/exercise.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ defmodule Workshop.Exercise.FirstExercise do
# given `@task`.
@description """
Write a FizzBuzz program without if/unless/case etc. The FizzBuzz program
outputs numbers 1 - 100. Each number which can be divided by 5 should be
replaced by "fizz", each multiple number of 3 should be replaced by "buzz"
and each number which can be divided by both should be replace by "fizzbuzz"
outputs numbers 1 - 100. Each number that is divisible by 3 should be
replaced by "Fizz", each number divisible by 5 should be replaced by "Buzz"
and each number that is divisible by both should be replace by "FizzBuzz"

# What's next?
Get the task for this exercise by executing `mix workshop.task`. When you are
Expand All @@ -26,9 +26,9 @@ defmodule Workshop.Exercise.FirstExercise do

@task """
Write a FizzBuzz program without if/unless/case etc. The FizzBuzz program
outputs numbers 1 - 100. Each number which can be divided by 5 should be
replaced by "fizz", each multiple number of 3 should be replaced by "buzz"
and each number which can be divided by both should be replace by "fizzbuzz"
outputs numbers 1 - 100. Each number that is divisible by 3 should be
replaced by "Fizz", each number divisible by 5 should be replaced by "Buzz"
and each number that is divisible by both should be replace by "FizzBuzz"
"""

@hint [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule FizzBuzz do
import Kernel, except: [if: 2, unless: 2, case: 2]

def translate(number) when rem(number, 15) == 0, do: "fizzbuzz"
def translate(number) when rem(number, 5) == 0, do: "fizz"
def translate(number) when rem(number, 3) == 0, do: "buzz"
def translate(number) when rem(number, 15) == 0, do: "FizzBuzz"
def translate(number) when rem(number, 5) == 0, do: "Buzz"
def translate(number) when rem(number, 3) == 0, do: "Fizz"
def translate(number), do: number
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ defmodule Workshop.Exercise.FirstExerciseCheck do
end

verify "verify FizzBuzz.translate(5)" do
(FizzBuzz.translate(5) == "fizz" && :ok) || {:error, "FizzBuzz.translate(5) == 'fizz', got #{FizzBuzz.translate(5)} "}
(FizzBuzz.translate(5) == "Buzz" && :ok) || {:error, "FizzBuzz.translate(5) == 'Buzz', got #{FizzBuzz.translate(5)} "}
end

verify "verify FizzBuzz.translate(3)" do
(FizzBuzz.translate(3) == "buzz" && :ok) || {:error, "FizzBuzz.translate(3) == 'buzz' expected, got #{FizzBuzz.translate(3)}"}
(FizzBuzz.translate(3) == "Fizz" && :ok) || {:error, "FizzBuzz.translate(3) == 'Fizz' expected, got #{FizzBuzz.translate(3)}"}
end

verify "verify FizzBuzz.translate(45)" do
(FizzBuzz.translate(45) == "fizzbuzz" && :ok) || {:error, "FizzBuzz.translate(45) 'fizzbuzz' expected, got #{FizzBuzz.translate(45)}"}
(FizzBuzz.translate(45) == "FizzBuzz" && :ok) || {:error, "FizzBuzz.translate(45) 'FizzBuzz' expected, got #{FizzBuzz.translate(45)}"}
end
end
7 changes: 5 additions & 2 deletions studygroup_002/.workshop/exercises/arrange/exercise.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule Workshop.Exercise.Arrange do
The sliced veggies & meat dices have to be arranged so next person can quickly
combine them into a delicious high cuisine item. Implement arrange function which
given a list of (unarranged) :vegetable_slices and :meat_dices arranges them alternately
starting with a :vegetable_slice
starting with a :vegetable_slice. You can assume that for this exercise the list
will have an equal number of meat_dice and vegetable_slices.

# What's next?
Take a look into arranger.exs and implement missing stuff. When you are
Expand All @@ -27,7 +28,9 @@ defmodule Workshop.Exercise.Arrange do
@task """
Implement arrange function which
given a list of (unarranged) :vegetable_slices and :meat_dices arranges them alternately
starting with a :vegetable_slice
starting with a :vegetable_slice.
You can assume that for this exercise the list
will have an equal number of meat_dice and vegetable_slices.
"""

@hint [
Expand Down