{
  "id": 8387561,
  "title": "What Math Actually Buys You: Optimizing a Rock-Paper-Scissors Game in C",
  "url": "https://urgent.news/2026/09/19/what-math-actually-buys-you-optimizing-a-rock-paper-scissors-game-in-c",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-19T05:11:18.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/david_essien/what-math-actually-buys-you-optimizing-a-rock-paper-scissors-game-in-c-hnp"
  },
  "original_language": "en",
  "account": "In the pursuit of understanding the practical applications of mathematics in programming, I delved into my archived C projects, specifically two Rock-Paper-Scissors games I had written years ago. The objective was to compare these implementations, focusing on the role of mathematical concepts in the code.\n\nThe first iteration, a naive version, demonstrated a critical instance where mathematical principles, albeit inadvertently, guided the code's functionality. The main function initiated by seeding the random number generator with the current time, generating a random integer between 1 and 3 (representing Rock, Paper, Scissors), and entering a loop until one of the players reached 3 points.\n\nThe loop condition, however, contained an error - the variable 'option' was declared but not initialized before being checked. This resulted in undefined behavior due to the reading of a garbage value, which in this case, almost invariably wouldn't equal 1, 2, or 3. Therefore, the loop commenced as intended, although this was pure luck rather than a robust design.\n\nThe heart of the game's decision-making process resided in the 'check_rules' function, which used a switch statement to determine the winner based on the player's and computer's options. The function carefully handled each possible scenario, returning 0 if the game was a tie, 1 if the player won, and -1 if the computer won.\n\nThis example served to underscore the point that while programming provides the flexibility to creatively solve problems, the knowledge base is the fuel that powers this creativity. In this case, the mathematical underpinnings of the switch statement provided a precise method to express the game's rules, enabling clear reasoning and decision-making in the code.\n\nThe full source code of both versions is publicly available on GitHub for further exploration.",
  "summary": "I was looking through my old projects and found a couple of Rock-Paper-Scissors games I wrote in C a few years back. Why more than one? Because programming is fun, but also because I was experimenting. We're going to look at both versions and talk about how math actually shows up in code. This will not be some generic \"you should know math\" lecture, but a before/after comparison grounded in my…",
  "key_points": [
    "Naive version seeded random with time, generated 1-3 for Rock-Paper-Scissors",
    "Undefined behavior due to uninitialized option variable, loop ran by luck",
    "Switch statement in checkrules function applied mathematical rules to game logic"
  ],
  "editors_take": "The use of mathematical concepts in programming enables clear reasoning and decision-making, as seen in the Rock-Paper-Scissors game's switch statement that precisely expressed the game's rules.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}