Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

12 Coins Puzzle - Manim Animation Project

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.

🎯 Project Overview

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

πŸš€ Setup Instructions

Prerequisites

  • Python 3.7 or higher
  • Git (for cloning the repository)

Mac Setup

  1. Clone the repository

    git clone https://github.com/ronalking182/csc309.git
    cd csc309/coins_puzzle_manim
  2. Create and activate virtual environment

    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Install system dependencies for Manim

    brew install ffmpeg
    brew install cairo
    brew install pkg-config
    brew install pango

Windows Setup

  1. Clone the repository

    git clone https://github.com/ronalking182/csc309.git
    cd csc309\coins_puzzle_manim
  2. Create and activate virtual environment

    python -m venv venv
    venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Install system dependencies for Manim

    • Download and install ffmpeg
    • Add ffmpeg to your system PATH
    • Install MiKTeX for LaTeX support (optional but recommended)

🎬 Running the Animations

Option 1: Render All Scenes at Once

python render_all.py

This will render all 12 scenes and save them to the media/videos/ directory.

Option 2: Render Individual Scenes

# 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 Scene1Definition

Option 3: Using the Main Script

python main.py

This provides a menu of available scenes and rendering options.

πŸ“½οΈ Scene Overview

Scene 1: Definition (scene1_definition.py)

  • 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

Scene 2: Why It Matters (scene2_why_it_matters.py)

  • Title: "Why This Puzzle Matters"
  • Content: Explains the importance of systematic thinking and algorithmic approaches
  • Key Message: Connects to broader problem-solving skills

Scene 3: Key Insight (scene3_key_insight.py)

  • 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

Scene 4: Math Behind (scene4_math_behind.py)

  • 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)

Scene 5: Strategy (scene5_strategy.py)

  • Title: "The Winning Strategy"
  • Content: Outlines the systematic approach to solve the puzzle
  • Key Message: Divide and conquer with information-maximizing weighings

Scene 6: First Weighing (scene6_first_weighing.py)

  • Title: "The First Weighing"
  • Content: Demonstrates the optimal first weighing (4 vs 4 coins)
  • Key Message: How to interpret the three possible outcomes

Scene 7: Interpretation (scene7_interpretation.py)

  • Title: "Interpreting Results"
  • Content: Shows how to analyze weighing results and narrow down possibilities
  • Key Message: Each result provides specific information about coin groups

Scene 8: Logic Tree (scene8_logic_tree.py)

  • Title: "Why Random Guessing Fails"
  • Content: Demonstrates the inefficiency of random approaches
  • Key Message: Systematic thinking beats random guessing

Scene 9: Why Random Fails (scene9_why_random_fails.py)

  • Title: "Think Like a Detective"
  • Content: Uses detective analogy to explain systematic investigation
  • Key Message: Methodical approach leads to guaranteed success

Scene 10: Real Life (scene10_real_life.py)

  • Title: "The Big Lesson"
  • Content: Summarizes the key learning points from the puzzle
  • Key Message: Algorithmic thinking is powerful and transferable

Scene 11: Big Lesson (scene11_big_lesson.py)

  • 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

Scene 12: Ending (scene12_ending.py)

  • Title: "Final Thought"
  • Content: Concludes with the power of algorithmic thinking and Computer Science
  • Key Message: CS thinking transforms how we approach problems

🎨 Customization Options

Rendering Quality

  • -pql: Low quality (fastest, good for testing)
  • -pqm: Medium quality
  • -pqh: High quality (recommended for final output)
  • -pqk: 4K quality (slowest, best quality)

Output Formats

  • Default: MP4 video files
  • Add --format gif for GIF output
  • Add --format png for image sequence

πŸ“ Project Structure

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

πŸ› οΈ Troubleshooting

Common Issues

  1. ffmpeg not found

    • Mac: brew install ffmpeg
    • Windows: Download from ffmpeg.org and add to PATH
  2. Cairo/Pango errors

    • Mac: brew install cairo pango pkg-config
    • Windows: Install through package managers or precompiled binaries
  3. LaTeX errors

    • Install MiKTeX (Windows) or MacTeX (Mac)
    • Ensure LaTeX is in your system PATH
  4. Memory issues during rendering

    • Use lower quality settings (-pql instead of -pqh)
    • Close other applications
    • Render scenes individually instead of all at once

πŸŽ“ Educational Value

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

🀝 Contributing

Feel free to:

  • Add new scenes or improve existing ones
  • Translate scenes to other languages
  • Create alternative solution approaches
  • Add interactive elements or quizzes

πŸ“„ License

This project is open source and available under the MIT License.


Happy animating! 🎬✨

About

manim

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages