Math buys you a smaller, easier-to-check rule, not automatic speed. That is the honest lesson of David Essien’s two C versions of Rock-Paper-Scissors. One spells out every matchup with branches. The other notices that the game is a cycle of three and encodes it as a 3×3 table or a single modular expression. The code gets shorter and easier to extend. The author’s own benchmarks show the speed ranking changing with compiler settings, and in a game that waits on a human, none of it is noticeable.
If you are a new CS student or a self-taught developer and you don’t quite buy that math matters day to day, this small example is a fair test case.
As an Amazon Associate I earn from qualifying purchases.
The starting point: spelling out every case
The first implementation uses a switch that enumerates all nine pairings of two players’ choices. It works, and every case is easy to read in isolation. The cost is that correctness depends on you checking nine branches by eye, and a larger game multiplies the branches: Rock-Paper-Scissors-Lizard-Spock has 25 pairings.
A bug hiding in the starter loop
The article’s first example declares option without initializing it, then reads it in the loop condition before any input has been assigned. Reading an uninitialized local in C is undefined behavior, so the loop may start or skip depending on whatever happens to be in memory. Initialize it to a known value (or use a do { ... } while loop that reads input before testing). This is a correctness defect, not a harmless way to start a loop.
#1 Best Overall
- Vivid Variety: enjoy a vibrant mix of colors—red, blue, yellow, and green—randomly distributed among the 50 pcs rock paper scissors random toys in each pack; These colorful creations are ideal for brightening up parties, holidays, or any game night
- Pocket Sized and Lightweight: a toy that fits in your pocket, each rock-paper-scissors toy measures about 2 x 1.5 inches and weighs about 0.35 ounce/ 10 g; Its mini egg shaped shape and chain design make it easy to carry on a keychain or backpack, ensuring fun is always within reach
- Quality Plastic for Longevity: crafted from quality plastic, these mini game keychains boast a smooth finish with no sharp edges, offering safe and reliable playtime; The sturdy material ensures they withstand endless rounds of fun, while the comfortable grip makes each game a pleasure to play
- No Batteries Needed: the random rock paper scissors toy adopts an innovative push button design, does not require batteries, is fair and just, and increases the fun of the game; Simply press the black button to randomly display ''rock'', ''paper'', ''scissors'', adding a thrilling twist to this classic game
- Toys, Keychains, and More: not only a fun game prop, but also a keychain, fashion accessory, Halloween party supplies, gifts, rewards, or goodie stuffers; It is suitable for birthday parties, Christmas stocking stuffers, interactions, music festivals, stress relief parties, graduation parties, weddings, trick toys, celebrations, festivals, holidays, and other fun spoof gifts, ideal for both gifts and personal use
How math helps: seeing the cycle
Number the moves Rock = 0, Paper = 1, Scissors = 2. Each pair then has exactly one of three outcomes: win, draw or loss. Because the game is a cycle, the outcome depends only on the relationship between the two numbers, not on nine unrelated facts.
Version 1: an outcome table
int rules_matrix[3][3] = {{0, -1, 1}, {1, 0, -1}, {-1, 1, 0}};
The article encodes 1 as a win, 0 as a draw and -1 as a loss. Read it as rules_matrix[x][y], where the row x is the player whose outcome you want. Check row 0 (Rock): against Rock it is a draw (0), against Paper a loss (-1), against Scissors a win (1). Swap the meaning of row and column and every win becomes a loss, so document the convention next to the table.
Lookup is a single index, but only if both indices are within 0 to 2. Validate input before indexing; an out-of-range value reads outside the array.
Recommended Free Tools
Rank #2
- THINK. THROW. WIN! – Throw Hands turns “Rock, Paper, Scissors” into an absurdly fast and absolutely chaotic card game for 2–8 players! With NO turns and NO time to think, players pile up “Rock,” “Paper,” and “Scissors” cards by throwing down the winning symbol again and again in a ridiculously funny race to shed all your cards first!
- NO TURNS OR TIME – In this free-for-all card-shedding game, you’ll need a quick mind and even quicker hands to win. Watch the last card played, then be the first player to throw down a card with the symbol that beats it. Rock beats Scissors. Paper beats Rock. Scissors beats Paper. Don’t wait for anyone, because they’re not waiting for you!
- 60 SECONDS OF CHAOS – With players shouting symbols, cards flying everywhere, and no time to hesitate, this 60-second card game hilariously pushes everyone’s mental reflexes to the edge!
- FAST AND FUN – Throw Hands is ridiculously easy to learn, insanely fast to play, and guaranteed to get laughs as it turns any room into a loud, competitive mess. It’s the perfect game for turning up the energy at family and friends’ game night!
- 2–8 Players | Ages 7+ | 60 Seconds Play Time
Version 2: a modular expression
The article also gives this formula for the same convention:
((x - y + 4) % 3) - 1
Why it works: x - y is the distance around the cycle. The + 4 does two jobs. Adding 3 keeps the value non-negative (for inputs 0 to 2 the smallest value is 2), which sidesteps C’s negative-remainder behavior, and the extra 1 shifts the three residues 0, 1, 2 so that subtracting 1 gives -1, 0, 1. Spot checks against the matrix: (0,1) gives (3 % 3) – 1 = -1; (0,2) gives (2) – 1 = 1; (1,0) gives (5 % 3) – 1 = 1; (0,0) gives (4 % 3) – 1 = 0. All agree.
This only holds for inputs 0, 1, 2 under that ordering. It is not a general-purpose formula you can apply to arbitrary values without validation.
Rank #3
- It's the fast, fun card version of the classic game of Rock Paper Scissors, now available in a bilingual version
- Each player lays down a card - the player with the stronger card takes both
- The player who collects the most cards wins!
- Quick and easy gameplay allows kids to play again and again
- For 2 players, ages 4 and up
Comparing the three approaches
| Axis | Switch | Table | Modular expression |
|---|---|---|---|
| Rule representation | Explicit cases | Indexed outcome data | Arithmetic |
| Easy to verify | Each case readable, nine to check | Nine numbers; row/column meaning must be known | Short, but needs the explanation above |
| Growing the gesture set | New branches for every pairing | Larger table, but you must still define every outcome | Only if the new game is also a clean cycle |
| Failure modes | Missing or wrong case | Out-of-range index; reversed convention | Out-of-range input; negative remainders if the offset is dropped |
The article describes extending the table and the option list instead of adding a case per rule. That is a real gain, but not free: a bigger table still needs correct rules, and the indexing scheme must still make sense. The modulo trick generalizes to odd-sized cycles where each move beats half the others, not to every rule set.
Free tools Windows power users keep installed
One-click scans. No signup required.
What the benchmarks showed
All figures below are David Essien’s reported local results. The source does not state the machine or full compiler version, so treat them as one author’s measurements, not a claim about C, compilers or lookup tables in general.
Unoptimized build, switch versus table
Each function was called 100 million times, three runs each.
Rank #4
- FAST-PACED STRATEGIC CARD GAME FOR FAMILY & FRIENDS: SHOOTS! puts a nostalgic twist on classic trick-taking games with Rock, Paper, Scissors suits. Whether you're hosting game night or looking for a competitive party game, this easy-to-learn, fast-play card game is perfect for ages 8 and up.
- UNIQUE ROCK, PAPER, SCISSORS SUITS & GAMEPLAY: Ditch the traditional Spades and play with Rock, Paper, and Scissors suits! Outscore your opponent using clever card play, the RPS hierarchy, and the powerful SHOOT move to win books and collect high-value point cards like the Joker and Deuce.
- 2 OR 4 PLAYER PARTY CARD GAME FOR ALL AGES: Designed for 2 or 4 players, this engaging card game brings friends and family together. Great for kids, teens, and adults, SHOOTS! blends strategy and luck into rounds that last just 20–30 minutes—ideal for quick game nights or travel play.
- WHAT’S IN THE BOX – COMPLETE GAME SET: Includes 40 premium cards featuring three suits (Rock, Paper, Scissors), one Joker, a score pad, and a rule sheet. Every card is ranked for strategic play, from Deuce to 3. Compact and portable—take this versatile deck anywhere for hours of fun.
- SCORE POINTS, WIN BOOKS, RULE THE TABLE: Each round, players compete to capture the highest-value cards using strategy and Rock-Paper-Scissors logic. Joker, Deuce, and Ace score big! First to 175 points wins. A competitive card game perfect for casual play or intense game night battles.
| Version | Run times (s) | Mean of the three (my arithmetic) |
|---|---|---|
| Switch | 0.343620, 0.342246, 0.340185 | about 0.342 |
| Matrix | 0.275987, 0.272867, 0.272581 | about 0.274 |
The author summarizes this as roughly 0.7 ns per call, about 20%, and immediately notes that it is negligible in a game paced by a human.
With -O2
| Version | Run times (s) | Mean (my arithmetic) |
|---|---|---|
| Switch | 0.119248, 0.120751, 0.122600 | about 0.121 |
| Matrix | 0.133597, 0.128811, 0.132499 | about 0.132 |
The ranking flipped. In the author’s words: “The only thing I changed was adding the build flag, and switch went from consistently losing to consistently winning.”
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteThree-way comparison: inlined versus real calls
| Condition (ns per call) | Switch | Matrix | Modular |
|---|---|---|---|
| Forced inline | 1.293 | 1.339 | 1.261 |
| Real function calls | 2.261 | 1.697 | 1.793 |
The author says an AI helped write the harness for this comparison and does not try to explain the rankings beyond the evidence. Neither should you: the order changes with inlining, so no single winner emerges.
Best Value
So what does math actually buy you?
The author’s conclusion is that recognizing the modular structure gave a solution that was “simultaneously simpler to read, easier to extend, and measurably faster.” The first two hold up well. The third needs the caveat above: it was measurable in one unoptimized build and reversed or blurred in others. In a program that spends nearly all its time waiting for a keypress, a few nanoseconds per rules check change nothing the player can perceive.
The durable payoff is conceptual. Seeing the cycle turned nine special cases into one rule you can verify with four spot checks. When you want speed, measure under your real build flags and inlining conditions, and only after the code is correct, with initialized variables and validated indices.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →




