https://github.com/sleekpanther/set-game
Algorithm to find possible sets in the game Set using an iterative implementation of n choose 3 for combinations
https://github.com/sleekpanther/set-game
combination combinations combinatorics n-choose-k noah noah-patullo noahpatullo pattullo pattulo patullo patulo set set-game sets
Last synced: about 2 months ago
JSON representation
Algorithm to find possible sets in the game Set using an iterative implementation of n choose 3 for combinations
- Host: GitHub
- URL: https://github.com/sleekpanther/set-game
- Owner: SleekPanther
- Created: 2017-11-27T21:47:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-28T13:22:15.000Z (almost 8 years ago)
- Last Synced: 2025-03-05T02:43:01.981Z (7 months ago)
- Topics: combination, combinations, combinatorics, n-choose-k, noah, noah-patullo, noahpatullo, pattullo, pattulo, patullo, patulo, set, set-game, sets
- Language: Java
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Set Game
An algorithm to find valid sets 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.# Java Version
The more robust version is in [SetGame.java](SetGame.java)## Card Objects
- The `Card` class defines a data structure to hold 4 pieces of information about a card: **number, shape, shading & color**
- All are represented as **integers** for ease of calculation
- Displaying a card color would just be defining some draw() method that showed a different color based on the integer value## N Choose 3 Algorithm
While computationally intractable, finding all possible subsets of size 3 can be done iteratively without too much trouble- `printCombinations()` extracts the same logic from `findSets()` to find all subsets of size 3 using 3 nested loops
- The trick to to have the inner loop start it's index at 1 greater than the parent loop's current index
- This pattern could be continued to find combinations for specific values of **k**
- Doesn't work for arbitrary **k** because that would likely involve a recursive implementation## Checking For Valid Sets
- Cards have 4 attributes and each attribute must either be the same for all 3 cards, or all different
- 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)`## Python Version
The 1st attempt where I came up with the n choose 3 implementation