15 Jun 2024C++ / Python / TypeScriptEasy

Nim Game

Collected C++, Python, TypeScript solutions for nim game. Add a dedicated write-up later if you want deeper notes.

auto-generated entry for Nim Game. the solution files are available below.

solution files

  • C++ nim-game/synced-solution.cpp
  • Python nim-game/synced-solution.py
  • TypeScript nim-game/synced-solution.ts

Solution files

Pythonnim-game/synced-solution.py
def canWinNim(n: int) -> bool:
    return n % class="syntax-number">4 != class="syntax-number">0
C++nim-game/synced-solution.cpp
class Solution {
public:
    bool canWinNim(int n) {
        return n % class="syntax-number">4 != class="syntax-number">0;
    }
};
TypeScriptnim-game/synced-solution.ts
function canWinNim(n: number): boolean {
    return n % class="syntax-number">4 !== class="syntax-number">0;
}