
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Explore the link between mathematics and algorithms in competitive programming and math puzzles, focusing on combinatorial game theory, rigorous proofs, and the mathematics behind algorithm design through examples and quizzes.
Explore combinatorial game theory, a branch of mathematics and theoretical computer science, studying impartial sequential games with piles of stones, perfect information, and winning positions under optimal play.
Model Nim's game as a directed acyclic graph, where vertices are states and edges are moves; a state is losing, and others are winning if they reach a losing state.
Explore Nim's game and its winning strategy. Represent the state as a multiset of piles and use xor of pile sizes to mark winning positions, with induction from empty piles.
Demonstrate a straightforward code implementation for Nim's game: read the number of piles, process each pile, assess if the starting state is winning, and print yes or no.
Explore an impartial combinatorial game with stones on stairs, moving any positive number to the next stair. The xor of pile sizes determines the winner, via mirroring.
This example shows a code implementation for a problem restricted to odd pile sizes, concluding that if the outcome is non-zero, the first player wins and prints yes; otherwise no.
Explore Sprague-Grundy values and mex-based reasoning for impartial games, showing how losing and winning states arise, and how the nim-sum (xor) of pile SG values determines the outcome.
Define a memoized sg function with x and max size m to enumerate moves and find the minimal integer not in the set; non-zero means a win.
Analyze a USACO gold style game of removing stones from piles with divisibility constraints, determine first-player winning moves, and use prefix sums for linear-time counting.
Implement a code solution that counts power sizes with a prefix sum, tracks occurrences, and determines winning or losing positions by analyzing odd powers and multiples.
Complete the end of the algorithms in competitive programming game theory module, acknowledge combinatorial game theory as an abstract concept with little calculation, and preview computation-heavy topics to come.
This is a series of courses on popular algorithms used especially in the field of competitive programming!
Competitive programming is a mental sport that tests students on a variety of logical or mathematical problems, and the use of algorithms is essential in improving the efficiency of your solution.
The aim of competitive programming is to write source code of computer programs that are able to solve given problems. Typical such tasks belong to one of the following categories: combinatorics, number theory, graph theory, algorithmic game theory, computational geometry, string analysis, and data structures.
This course focuses not only on the implementation of algorithms but also on the mathematics behind these algorithms since they are requisite in understanding the correctness and efficiency of the algorithms. Specifically, rigid proofs for algorithms will be covered in this series of lectures.
This is the first course in the series Algorithms in Competitive Programming: Maths Puzzles II. In this course, we will be learning about combinatorial game theory, a rather niche topic in competitive programming. However, it is(arguably) one of the most interesting topics and there is more mathematical logic behind these combinatorial puzzles than you would have imagined.
If you find this course intriguing or you want to learn more about competitive programming algorithms, please look forward to future addition to the series!
A typical course structure is as follows:
- Problem description
- A naive approach
- Introducing the algorithm
- Mathematical proof of the correctness and efficiency of the algorithm
- A sample problem
- Short quiz
- Hands-on practice