2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,29 +1,28 @@
|
|||
{{omit from|GUISS}}
|
||||
|
||||
Set Puzzles are created with a deck of cards from the [[wp:Set (game)|Set Game™]]. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up. <br>
|
||||
Set Puzzles are created with a deck of cards from the [[wp:Set (game)|Set Game™]]. The object of the puzzle is to find sets of 3 cards in a rectangle of cards that have been dealt face up. <br><br>
|
||||
There are 81 cards in a deck.
|
||||
Each card contains a unique variation of the following four features: ''color, symbol, number and shading''.
|
||||
|
||||
; there are three colors: '''red''', '''green''', or '''purple'''
|
||||
* there are three colors:<br> ''red, green, purple''<br><br>
|
||||
|
||||
; there are three symbols: '''oval''', '''squiggle''', or '''diamond'''
|
||||
* there are three symbols:<br> ''oval, squiggle, diamond''<br><br>
|
||||
|
||||
; there is a number of symbols on the card: '''one''', '''two''', or '''three'''
|
||||
* there is a number of symbols on the card:<br> ''one, two, three''<br><br>
|
||||
|
||||
; there are three shadings: '''solid''', '''open''', or '''striped'''
|
||||
* there are three shadings:<br> ''solid, open, striped''<br><br>
|
||||
|
||||
Three cards form a ''set'' if each feature is either the same on each card, or is different on each card. <br>
|
||||
For instance: all 3 cards are red, all 3 cards have a different symbol, all 3 cards have a different number of symbols, all 3 cards are striped.
|
||||
Three cards form a ''set'' if each feature is either the same on each card, or is different on each card. For instance: all 3 cards are red, all 3 cards have a different symbol, all 3 cards have a different number of symbols, all 3 cards are striped.
|
||||
|
||||
There are two degrees of difficulty: [http://www.setgame.com/set/rules_basic.htm ''basic''] and [http://www.setgame.com/set/rules_advanced.htm ''advanced'']. The basic mode deals 9 cards, that contain exactly 4 sets; the advanced mode deals 12 cards that contain exactly 6 sets.
|
||||
|
||||
There are two degrees of difficulty: [http://www.setgame.com/set/rules_basic.htm ''basic''] and [http://www.setgame.com/set/rules_advanced.htm ''advanced'']. <br>
|
||||
The basic mode deals 9 cards, that contain exactly 4 sets;
|
||||
the advanced mode deals 12 cards that contain exactly 6 sets.
|
||||
When creating sets you may use the same card more than once.
|
||||
<br><br>
|
||||
|
||||
;The task:
|
||||
Is to write code that deals the cards (9 or 12, depending on selected mode) from a shuffled deck in which the total number of sets that could be found is 4 (or 6, respectively); and print the contents of the cards and the sets.
|
||||
;Task
|
||||
Write code that deals the cards (9 or 12, depending on selected mode) from a shuffled deck in which the total number of sets that could be found is 4 (or 6, respectively); and print the contents of the cards and the sets.
|
||||
|
||||
For instance:
|
||||
For instance:<br><br>
|
||||
|
||||
'''DEALT 9 CARDS:'''
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ For instance:
|
|||
:red, three, oval, open
|
||||
|
||||
:red, three, diamond, solid
|
||||
|
||||
<br>
|
||||
'''CONTAINING 4 SETS:'''
|
||||
|
||||
:green, one, oval, striped
|
||||
|
|
@ -73,3 +72,4 @@ For instance:
|
|||
:purple, two, squiggle, open
|
||||
|
||||
:purple, three, oval, open
|
||||
<br><br>
|
||||
|
|
|
|||
54
Task/Set-puzzle/Elixir/set-puzzle.elixir
Normal file
54
Task/Set-puzzle/Elixir/set-puzzle.elixir
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
defmodule RC do
|
||||
def set_puzzle(deal, goal) do
|
||||
{puzzle, sets} = get_puzzle_and_answer(deal, goal, produce_deck)
|
||||
IO.puts "Dealt #{length(puzzle)} cards:"
|
||||
print_cards(puzzle)
|
||||
IO.puts "Containing #{length(sets)} sets:"
|
||||
Enum.each(sets, fn set -> print_cards(set) end)
|
||||
end
|
||||
|
||||
defp get_puzzle_and_answer(hand_size, num_sets_goal, deck) do
|
||||
hand = Enum.take_random(deck, hand_size)
|
||||
sets = get_all_sets(hand)
|
||||
if length(sets) == num_sets_goal do
|
||||
{hand, sets}
|
||||
else
|
||||
get_puzzle_and_answer(hand_size, num_sets_goal, deck)
|
||||
end
|
||||
end
|
||||
|
||||
defp get_all_sets(hand) do
|
||||
Enum.filter(comb(hand, 3), fn candidate ->
|
||||
List.flatten(candidate)
|
||||
|> Enum.group_by(&(&1))
|
||||
|> Map.values
|
||||
|> Enum.all?(fn v -> length(v) != 2 end)
|
||||
end)
|
||||
end
|
||||
|
||||
defp print_cards(cards) do
|
||||
Enum.each(cards, fn card ->
|
||||
:io.format " ~-8s ~-8s ~-8s ~-8s~n", card
|
||||
end)
|
||||
IO.puts ""
|
||||
end
|
||||
|
||||
@colors ~w(red green purple)a
|
||||
@symbols ~w(oval squiggle diamond)a
|
||||
@numbers ~w(one two three)a
|
||||
@shadings ~w(solid open striped)a
|
||||
|
||||
defp produce_deck do
|
||||
for color <- @colors, symbol <- @symbols, number <- @numbers, shading <- @shadings,
|
||||
do: [color, symbol, number, shading]
|
||||
end
|
||||
|
||||
defp comb(_, 0), do: [[]]
|
||||
defp comb([], _), do: []
|
||||
defp comb([h|t], m) do
|
||||
(for l <- comb(t, m-1), do: [h|l]) ++ comb(t, m)
|
||||
end
|
||||
end
|
||||
|
||||
RC.set_puzzle(9, 4)
|
||||
RC.set_puzzle(12, 6)
|
||||
Loading…
Add table
Add a link
Reference in a new issue