Skip to content

Commit d6f4c21

Browse files
authored
Update README.md
1 parent f889db7 commit d6f4c21

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
# set-game
1+
# Set Game
2+
An algorithm to find valid sets in a given deck in the [Game Set](https://en.wikipedia.org/wiki/Set_(game)). This isn't a complete game, just the logic & algorithm to check if a valid set exists so that a hint can be provided.
3+
4+
# Java Version
5+
The more robust version is in [SetGame.java](SetGame.java)
6+
7+
## Card Objects
8+
- The `Card` class defines a data structure to hold 4 pieces of information about a card: **number, shape, shading & color**
9+
- All are represented as **integers** for ease of calculation
10+
- Displaying a card color would just be defining some draw() method that showed a different color based on the integer value
11+
12+
## N Choose 3 Algorithm
13+
While computationally intractable, finding all possible subsets of size 3 can be done iteratively without too much trouble
14+
15+
- `printCombinations()` extracts the same logic from `findSets()` to find all subsets of size 3 using 3 nested loops
16+
- The trick to to have the inner loop start it's index at 1 greater than the parent loop's current index
17+
- This pattern could be continued to find combinations for specific values of **k**
18+
- Doesn't work for arbitrary **k** because that would likely involve a recursive implementation
19+
20+
## Checking For Valid Sets
21+
- Cards have 4 attributes and each attribute must either be the same for all 3 cards, or all different
22+
- Since **number, shape, shading & color** are all integers, checking valid sets is done by examining each attribute and passing the 3 values to `areAllEqual(int num1, int num2, int num3)` and `areAllDifferent(int num1, int num2, int num3)`
23+
24+
25+
## Python Version
26+
The 1st attempt where I came up with the n choose 3 implementation

0 commit comments

Comments
 (0)