An educational animation series explaining the classic 12 coins puzzle using Manim (Mathematical Animation Engine). This project demonstrates algorithmic thinking, problem-solving strategies, and the power of systematic approaches.
The 12 coins puzzle is a classic problem where you have 12 identical-looking coins, but one is different (either heavier or lighter). Using only a balance scale and 3 weighings, you must identify the odd coin and determine if it's heavier or lighter than the others.
This project creates 12 animated scenes that walk through:
- Problem definition and constraints
- Why naive approaches fail
- The optimal solution strategy
- Real-world applications of the thinking process
- Python 3.7 or higher
- Git (for cloning the repository)
-
Clone the repository
git clone https://github.com/ronalking182/csc309.git cd csc309/coins_puzzle_manim -
Create and activate virtual environment
python3 -m venv venv source venv/bin/activate -
Install dependencies
pip install -r requirements.txt
-
Install system dependencies for Manim
brew install ffmpeg brew install cairo brew install pkg-config brew install pango
-
Clone the repository
git clone https://github.com/ronalking182/csc309.git cd csc309\coins_puzzle_manim -
Create and activate virtual environment
python -m venv venv venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Install system dependencies for Manim
python render_all.pyThis will render all 12 scenes and save them to the media/videos/ directory.
# Basic quality (faster rendering)
manim -pql scenes/scene1_definition.py Scene1Definition
# High quality (slower rendering)
manim -pqh scenes/scene1_definition.py Scene1Definition
# 4K quality (very slow)
manim -pqk scenes/scene1_definition.py Scene1Definitionpython main.pyThis provides a menu of available scenes and rendering options.
- Title: "The 12 Coins Puzzle"
- Content: Introduces the problem with 12 coins, explains that one is different (heavier or lighter)
- Key Message: Sets up the challenge and basic constraints
- Title: "Why This Puzzle Matters"
- Content: Explains the importance of systematic thinking and algorithmic approaches
- Key Message: Connects to broader problem-solving skills
- Title: "The Key Insight"
- Content: Reveals the crucial realization about information theory and binary encoding
- Key Message: Each weighing provides maximum information when designed properly
- Title: "The Math Behind"
- Content: Explains the mathematical foundation using information theory
- Key Message: 3 weighings can distinguish between 24 possibilities (12 coins Γ 2 states)
- Title: "The Winning Strategy"
- Content: Outlines the systematic approach to solve the puzzle
- Key Message: Divide and conquer with information-maximizing weighings
- Title: "The First Weighing"
- Content: Demonstrates the optimal first weighing (4 vs 4 coins)
- Key Message: How to interpret the three possible outcomes
- Title: "Interpreting Results"
- Content: Shows how to analyze weighing results and narrow down possibilities
- Key Message: Each result provides specific information about coin groups
- Title: "Why Random Guessing Fails"
- Content: Demonstrates the inefficiency of random approaches
- Key Message: Systematic thinking beats random guessing
- Title: "Think Like a Detective"
- Content: Uses detective analogy to explain systematic investigation
- Key Message: Methodical approach leads to guaranteed success
- Title: "The Big Lesson"
- Content: Summarizes the key learning points from the puzzle
- Key Message: Algorithmic thinking is powerful and transferable
- Title: "This Thinking Appears In"
- Content: Lists real-world applications of the puzzle's thinking process
- Key Message: Binary search, debugging, medical diagnosis, and more
- Title: "Final Thought"
- Content: Concludes with the power of algorithmic thinking and Computer Science
- Key Message: CS thinking transforms how we approach problems
-pql: Low quality (fastest, good for testing)-pqm: Medium quality-pqh: High quality (recommended for final output)-pqk: 4K quality (slowest, best quality)
- Default: MP4 video files
- Add
--format giffor GIF output - Add
--format pngfor image sequence
coins_puzzle_manim/
βββ scenes/ # All animation scene files
β βββ scene1_definition.py
β βββ scene2_why_it_matters.py
β βββ ... (scenes 3-12)
βββ media/ # Generated output files
β βββ videos/ # Rendered videos
β βββ images/ # Generated images
β βββ texts/ # Generated text assets
βββ main.py # Entry point with scene menu
βββ render_all.py # Batch rendering script
βββ test_scenes.py # Test all scene imports
βββ requirements.txt # Python dependencies
βββ README.md # This file
-
ffmpeg not found
- Mac:
brew install ffmpeg - Windows: Download from ffmpeg.org and add to PATH
- Mac:
-
Cairo/Pango errors
- Mac:
brew install cairo pango pkg-config - Windows: Install through package managers or precompiled binaries
- Mac:
-
LaTeX errors
- Install MiKTeX (Windows) or MacTeX (Mac)
- Ensure LaTeX is in your system PATH
-
Memory issues during rendering
- Use lower quality settings (
-pqlinstead of-pqh) - Close other applications
- Render scenes individually instead of all at once
- Use lower quality settings (
This project demonstrates:
- Algorithmic Thinking: Systematic problem-solving approaches
- Information Theory: How to maximize information gain
- Binary Encoding: Representing states with binary decisions
- Divide and Conquer: Breaking complex problems into manageable parts
- Real-world Applications: Connecting abstract concepts to practical scenarios
Feel free to:
- Add new scenes or improve existing ones
- Translate scenes to other languages
- Create alternative solution approaches
- Add interactive elements or quizzes
This project is open source and available under the MIT License.
Happy animating! π¬β¨