Skip to content

ChHsiching/josephus-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

็บฆ็‘Ÿๅคซ้—ฎ้ข˜ๅฏ่ง†ๅŒ–ๅทฅๅ…ท / Josephus Problem Visualizer

English | ไธญๆ–‡


ไธญๆ–‡

ๅŸบไบŽ Vue 3 + Vite ๆž„ๅปบ็š„ไบคไบ’ๅผ็บฆ็‘Ÿๅคซ้—ฎ้ข˜ๅฏ่ง†ๅŒ–ๅทฅๅ…ท๏ผŒๆ”ฏๆŒ้€่กŒไปฃ็ ่ฐƒ่ฏ•ๅ’ŒๅŠจ็”ปๆผ”็คบใ€‚

An interactive Josephus problem visualization tool built with Vue 3 + Vite, featuring line-by-line code debugging and animated demonstrations.

๐Ÿ’ก ้กน็›ฎไปทๅ€ผ / Project Value

่งฃๅ†ณๆ–ฐๆ‰‹ๅญฆไน ็บฆ็‘Ÿๅคซ้—ฎ้ข˜ๆ—ถ "ๅชๆ‡‚ไปฃ็ ไธๆ‡‚้€ป่พ‘" ็š„็—›็‚น

Solving the pain point of beginners learning the Josephus problem: "understanding code but not logic"

ๅพˆๅคšๅŒๅญฆๅœจๅญฆไน ็บฆ็‘Ÿๅคซ้—ฎ้ข˜ๆ—ถ๏ผŒ่ƒฝ็œ‹ๆ‡‚ไปฃ็ ็š„ๆฏไธ€่กŒ๏ผŒไฝ†่„‘ๆตท้‡Œๆƒณไธๅ‡บๅฎž้™…่ฟ่กŒ็š„็”ป้ขใ€‚่ฟ™ไธช้กน็›ฎ้€š่ฟ‡ "ๅทฆไพงไปฃ็  + ๅณไพง debug ๅผๅŠจ็”ป" ็š„ๆ–นๅผ๏ผŒ่ฎฉไฝ ๏ผš

Many students can understand each line of code when learning the Josephus problem, but cannot visualize the actual execution. This project uses a "left code + right debug-style animation" approach to help you:

  • ๐Ÿ‘€ ็œผ็œ‹ไปฃ็  / Watch Code: ๅทฆ่พน้ซ˜ไบฎๆ˜พ็คบๅฝ“ๅ‰ๆ‰ง่กŒๅˆฐๅ“ชไธ€่กŒ / Left side highlights the current execution line
  • ๐ŸŽฌ ่„‘่กฅ็”ป้ข / Visualize Process: ๅณ่พนๅŒๆญฅๆผ”็คบ้“พ่กจ่Š‚็‚น็š„็งปๅŠจๅ’Œๅˆ ้™ค / Right side synchronously demonstrates node movement and deletion
  • ๐Ÿ”— ๅปบ็ซ‹่”็ณป / Make Connections: ไปฃ็ ๅ’ŒๅŠจ็”ปๅฎžๆ—ถๅ…ณ่”๏ผŒ็†่งฃๆŠฝ่ฑก้€ป่พ‘ๅ˜ๅพ—่ฝปๆพ / Real-time connection between code and animation makes abstract logic easy to understand

ไธ้œ€่ฆๅฎ‰่ฃ…ไปปไฝ•่ฝฏไปถ๏ผŒๆ‰“ๅผ€็ฝ‘้กตๅฐฑ่ƒฝ็”จ๏ผ

No installation required - just open the web page and start using it!

๐Ÿ“ธ ๆผ”็คบๆˆชๅ›พ / Demo Screenshots

ๅœจ็บฟๆผ”็คบ / Live Demo: https://chhsiching.github.io/josephus-visualizer/

ๆœฌ้กน็›ฎๅทฒ้ƒจ็ฝฒๅˆฐ GitHub Pages๏ผŒ็‚นๅ‡ปไธŠๆ–น้“พๆŽฅๅณๅฏๆŸฅ็œ‹ๅฎž้™…่ฟ่กŒๆ•ˆๆžœใ€‚็•Œ้ขๅŒ…ๅซ๏ผš

This project is deployed on GitHub Pages. Click the link above to see it in action. The interface includes:

  • ๅทฆไพงไปฃ็ ้ขๆฟ / Left Code Panel: ๆ˜พ็คบ C ่ฏญ่จ€ไปฃ็ ๏ผŒ้ซ˜ไบฎๅฝ“ๅ‰ๆ‰ง่กŒ่กŒ / Displays C code with current execution line highlighted
  • ๅณไพงๅŠจ็”ป้ขๆฟ / Right Animation Panel: ๅฑ•็คบ็บฆ็‘Ÿๅคซ็ŽฏๅŠจ็”ป๏ผŒ่Š‚็‚น็งปๅŠจๅ’Œๅˆ ้™ค / Shows Josephus ring animation with node movement and elimination
  • ๅบ•้ƒจๆŽงๅˆถ้ขๆฟ / Bottom Control Panel: ๆ’ญๆ”พใ€ๆš‚ๅœใ€ๆญฅ่ฟ›ใ€้€Ÿๅบฆ่ฐƒ่Š‚ / Play, pause, step, and speed controls

โœจ ๅŠŸ่ƒฝ็‰นๆ€ง / Features

  • ๐ŸŽฏ ไบคไบ’ๅผๅฏ่ง†ๅŒ– / Interactive Visualization: ๅŸบไบŽ SVG ็š„ๅŒๅ‘ๅพช็Žฏ้“พ่กจๅฏ่ง†ๅŒ– / SVG-based circular linked list visualization with bidirectional pointers
  • ๐Ÿ“ ้€่กŒ่ฐƒ่ฏ• / Line-by-Line Debugging: GDB ้ฃŽๆ ผ็š„ C ไปฃ็ ๆ‰ง่กŒๆผ”็คบ๏ผŒๅฎžๆ—ถ้ซ˜ไบฎ / GDB-style C code execution with real-time highlighting
  • โฏ๏ธ ๅฎŒๆ•ดๆ’ญๆ”พๆŽงๅˆถ / Complete Playback Controls: ๆ”ฏๆŒๆ’ญๆ”พใ€ๆš‚ๅœใ€ๆญฅ่ฟ›ๅ’Œ้€Ÿๅบฆ่ฐƒ่Š‚ / Play, pause, step execution, and speed adjustment
  • ๐Ÿ”„ ๅฎžๆ—ถๅŠจ็”ป / Real-time Animation: ๅฑ•็คบ้“พ่กจๆž„ๅปบใ€่ฎกๆ•ฐใ€่Š‚็‚นๅˆ ้™ค็š„ๅฎŒๆ•ด่ฟ‡็จ‹ / Shows list construction, counting, and node elimination
  • ๐ŸŽจ ๅ“ๅบ”ๅผ่ฎพ่ฎก / Responsive Design: Gruvbox ๆš—่‰ฒไธป้ข˜๏ผŒๆ”ฏๆŒไธๅŒๅฑๅน•ๅฐบๅฏธ / Gruvbox dark theme with screen size support
  • ๐Ÿ“Š ่ฏฆ็ป†็Šถๆ€ๆ˜พ็คบ / Detailed Status Display: ๆ˜พ็คบๅฝ“ๅ‰ๅ›žๅˆใ€ๅทฒๅˆ ้™ค่Š‚็‚นใ€ๆ‰ง่กŒๆญฅ้ชค็ญ‰ / Shows current round, eliminated nodes, execution steps

๐Ÿš€ ๅฟซ้€Ÿๅผ€ๅง‹ / Quick Start

ๅœจ็บฟๆผ”็คบ / Live Demo

้กน็›ฎๅทฒ้ƒจ็ฝฒๅœจ GitHub Pages๏ผŒๅฏ็›ดๆŽฅ่ฎฟ้—ฎ๏ผš

The project is deployed on GitHub Pages and can be accessed directly:

https://chhsiching.github.io/josephus-visualizer/

ๆœฌๅœฐๅผ€ๅ‘ / Local Development

# Clone the project
git clone https://github.com/chhsiching/josephus-visualizer.git
cd josephus-visualizer

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

๐Ÿ“– ็ฎ—ๆณ•่ฏดๆ˜Ž / Algorithm Description

็บฆ็‘Ÿๅคซ้—ฎ้ข˜ / The Josephus Problem

็บฆ็‘Ÿๅคซ้—ฎ้ข˜ๆ่ฟฐ๏ผšn ไธชไบบ็ซ™ๆˆไธ€ๅœˆ๏ผŒไปŽๆŒ‡ๅฎš็š„ไบบๅผ€ๅง‹้กบๆ—ถ้’ˆๆŠฅๆ•ฐ๏ผŒๆ•ฐๅˆฐ k ็š„ไบบ่ขซๆท˜ๆฑฐ๏ผŒไธ‹ไธ€ไธชไบบ้‡ๆ–ฐไปŽ 1 ๅผ€ๅง‹ๆŠฅๆ•ฐใ€‚ๅฆ‚ๆญคๅพช็Žฏ๏ผŒ็›ดๅˆฐๆ‰€ๆœ‰ไบบ่ขซๆท˜ๆฑฐ๏ผŒ็กฎๅฎšๆท˜ๆฑฐ้กบๅบใ€‚

The Josephus problem describes: n people stand in a circle, starting from a specified person and counting clockwise. The person who counts to k is eliminated, and the next person restarts counting from 1. This continues until all are eliminated, determining the elimination order.

ๅฎž็Žฐ็ป†่Š‚ / Implementation Details

ๆœฌ้กน็›ฎไฝฟ็”จๅŒๅ‘ๅพช็Žฏ้“พ่กจๅฎž็Žฐ็บฆ็‘Ÿๅคซ้—ฎ้ข˜๏ผš

This project implements the Josephus problem using a doubly circular linked list:

  • ่Š‚็‚น็ป“ๆž„ / Node Structure: ๆฏไธชไบบ่กจ็คบไธบไธ€ไธช่Š‚็‚น๏ผŒๅŒ…ๅซ idใ€next ๅ’Œ pre ๆŒ‡้’ˆ / Each person as a node with id, next, and pre pointers
  • ้“พ่กจๆž„ๅปบ / List Construction: RingConstruct ๅ‡ฝๆ•ฐๅˆ›ๅปบ N ไธช่Š‚็‚น็š„ๅŒๅ‘ๅพช็Žฏ้“พ่กจ / Creates a doubly circular linked list with N nodes
  • ่ฎกๆ•ฐๆจกๅผ / Counting Pattern: ไฝฟ็”จ้‡ๅคๆจกๅผ [3, 5, 7, 13] ไฝœไธบๆฏ่ฝฎๆท˜ๆฑฐ็•Œ้™ / Uses repeating pattern [3, 5, 7, 13] as elimination bounds
  • ่ฎกๆ•ฐๅ‡ฝๆ•ฐ / Counting Function: count ๅ‡ฝๆ•ฐไปŽ่Š‚็‚นๅผ€ๅง‹่ฎกๆ•ฐ๏ผŒๆ‰พๅˆฐ่ฆๆท˜ๆฑฐ็š„่Š‚็‚น / Starts from a node and counts to find the elimination target
  • ่Š‚็‚น็งป้™ค / Node Removal: removeNode ๅ‡ฝๆ•ฐ็งป้™คๅฝ“ๅ‰่Š‚็‚นๅนถ้‡ๆ–ฐ่ฟžๆŽฅ้“พ่กจ / Removes current node and reconnects the list

ๅฏ่ง†ๅŒ–็ณป็ปŸ / Visualization System

  • ๅŒ็Žฏ็ฎญๅคด็ณป็ปŸ / Dual-Ring Arrow System: ๅค–็Žฏๆ˜พ็คบ next ๆŒ‡้’ˆ๏ผˆ้กบๆ—ถ้’ˆ๏ผ‰๏ผŒๅ†…็Žฏๆ˜พ็คบ prev ๆŒ‡้’ˆ๏ผˆ้€†ๆ—ถ้’ˆ๏ผ‰ / Outer ring shows next pointers (clockwise), inner ring shows prev pointers (counter-clockwise)
  • ๅŠจ็”ป้˜ถๆฎต / Animation Phases: ๅˆๅง‹ๅŒ–้˜ถๆฎตใ€่ฎกๆ•ฐ้˜ถๆฎตใ€็งป้™ค้˜ถๆฎตใ€ๅฎŒๆˆ้˜ถๆฎต / Initialization, counting, removal, and completion phases
  • ็Šถๆ€ๅŒๆญฅ / State Synchronization: ไปฃ็ ่กŒๅทไธŽๅŠจ็”ป็Šถๆ€็ฒพ็กฎๅŒๆญฅ / Precise synchronization between code line numbers and animation states

๐ŸŽฎ ไฝฟ็”จ่ฏดๆ˜Ž / Usage Instructions

ๅŸบๆœฌๆ“ไฝœ / Basic Operations

  1. ๆ’ญๆ”พ/ๆš‚ๅœ / Play/Pause: ็‚นๅ‡ปๆ’ญๆ”พๆŒ‰้’ฎๅผ€ๅง‹่‡ชๅŠจๆ‰ง่กŒ๏ผŒ็‚นๅ‡ปๆš‚ๅœๅœๆญข / Click play to start, pause to stop
  2. ๆญฅ่ฟ›ๆ‰ง่กŒ / Step Execution: ไฝฟ็”จๅ‰่ฟ›/ๅŽ้€€ๆŒ‰้’ฎ้€ๆญฅๆŸฅ็œ‹็ฎ—ๆณ•ๆ‰ง่กŒ / Use forward/backward buttons to step through
  3. ้€ŸๅบฆๆŽงๅˆถ / Speed Control: ๆ”ฏๆŒ 1xใ€2xใ€4x ๆ’ญๆ”พ้€Ÿๅบฆ / Supports 1x, 2x, 4x playback speeds
  4. ไปฃ็ ๅฏผ่ˆช / Code Navigation: ็‚นๅ‡ปๅทฆไพงไปฃ็ ้ขๆฟ็š„่กŒๅท่ทณ่ฝฌๅˆฐๅฏนๅบ”ๆญฅ้ชค / Click line numbers to jump to steps
  5. ้‡็ฝฎ / Reset: ็‚นๅ‡ป้‡็ฝฎๆŒ‰้’ฎ้‡ๆ–ฐๅผ€ๅง‹ๆผ”็คบ / Click reset to restart

็•Œ้ข่ฏดๆ˜Ž / Interface Description

  • ๅทฆไพง้ขๆฟ / Left Panel: ๆ˜พ็คบ C ไปฃ็ ๏ผŒ้ซ˜ไบฎๅฝ“ๅ‰ๆ‰ง่กŒ่กŒ / Displays C code with current execution line highlighted
  • ๅณไพง้ขๆฟ / Right Panel: ๅœ†ๅฝขๅฏ่ง†ๅŒ–๏ผŒๆ˜พ็คบ่Š‚็‚น็Šถๆ€ๅ’ŒๆŒ‡้’ˆๅ…ณ็ณป / Circular visualization showing node states and pointer relationships
  • ๅบ•้ƒจๆŽงๅˆถๆ  / Bottom Control Bar: ๆ’ญๆ”พๆŽงๅˆถใ€่ฟ›ๅบฆๆ˜พ็คบใ€้€Ÿๅบฆ่ฐƒ่Š‚็ญ‰ / Playback controls, progress display, speed adjustment
  • ไธญๅฟƒไฟกๆฏ / Center Information: ๆ˜พ็คบๅฝ“ๅ‰ๆ‰ง่กŒ้˜ถๆฎตๅ’Œๅ›žๅˆๆ•ฐ / Shows current execution phase and round number

๐Ÿ› ๏ธ ๆŠ€ๆœฏๆ ˆ / Tech Stack

  • ๅ‰็ซฏๆก†ๆžถ / Frontend Framework: Vue 3 (Composition API)
  • ๆž„ๅปบๅทฅๅ…ท / Build Tool: Vite
  • ๆ ทๅผ / Styling: SCSS + Gruvbox dark theme
  • ่ฏญๆณ•้ซ˜ไบฎ / Syntax Highlighting: Shiki
  • ๅฏ่ง†ๅŒ– / Visualization: SVG
  • ้ƒจ็ฝฒ / Deployment: GitHub Pages + GitHub Actions

๐Ÿ“ ้กน็›ฎ็ป“ๆž„ / Project Structure

josephus-visualizer/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/          # Vue components
โ”‚   โ”‚   โ”œโ”€โ”€ App.vue         # Main application component
โ”‚   โ”‚   โ”œโ”€โ”€ CodeDisplay.vue # Code display component
โ”‚   โ”‚   โ”œโ”€โ”€ CircleAnimation.vue # Animation component
โ”‚   โ”‚   โ”œโ”€โ”€ ControlPanel.vue    # Control panel component
โ”‚   โ”‚   โ”œโ”€โ”€ CircleNode.vue     # Node component
โ”‚   โ”‚   โ””โ”€โ”€ CircleLink.vue     # Link component
โ”‚   โ”œโ”€โ”€ utils/               # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ josephus-simulator.js # Algorithm simulator
โ”‚   โ””โ”€โ”€ styles/              # Style files
โ”‚       โ””โ”€โ”€ gruvbox-dark.scss    # Theme styles
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ joseph-ring-algorithm.c # C algorithm source code
โ”œโ”€โ”€ .github/workflows/       # GitHub Actions configuration
โ”‚   โ””โ”€โ”€ deploy.yml         # Auto-deployment configuration
โ””โ”€โ”€ README.md

โš™๏ธ ้…็ฝฎ / Configuration

  • ่Š‚็‚นๆ•ฐ้‡ / Node Count: ๅ›บๅฎš 20 ไธช่Š‚็‚น / Fixed at 20 nodes
  • ่ฎกๆ•ฐๆจกๅผ / Counting Pattern: ้‡ๅคๆจกๅผ [3, 5, 7, 13] / Repeating pattern [3, 5, 7, 13]
  • ๅŠจ็”ป้€Ÿๅบฆ / Animation Speed: ๆ”ฏๆŒ 1xใ€2xใ€4x ้€Ÿๅบฆ่ฐƒ่Š‚ / Supports 1x, 2x, 4x speed adjustment
  • ไธป้ข˜้…็ฝฎ / Theme Configuration: Gruvbox ๆš—่‰ฒไธป้ข˜ / Gruvbox dark theme

๐Ÿ“„ ่ฎธๅฏ่ฏ / License

ๆœฌ้กน็›ฎ้‡‡็”จ MIT ่ฎธๅฏ่ฏใ€‚

This project is licensed under the MIT License.

โ“ ๅธธ่ง้—ฎ้ข˜ / FAQ

Q1: ๅŠจ็”ปๅกไฝไธๅŠจไบ†ๆ€ŽไนˆๅŠž๏ผŸ / Animation stuck?

A: ๅˆทๆ–ฐ้กต้ขๅณๅฏใ€‚ๅฆ‚ๆžœ้—ฎ้ข˜ๆŒ็ปญ๏ผŒๅฐ่ฏ•้™ไฝŽๆ’ญๆ”พ้€Ÿๅบฆ๏ผˆๅˆ‡ๆขๅˆฐ 1x๏ผ‰ใ€‚

A: Refresh the page. If the issue persists, try reducing the playback speed (switch to 1x).

Q2: ่ƒฝไธ่ƒฝไฟฎๆ”นไบบๆ•ฐๆˆ–่ฎกๆ•ฐ่ง„ๅˆ™๏ผŸ / Can I change the number or counting rules?

A: ๅฝ“ๅ‰็‰ˆๆœฌๅ›บๅฎšไธบ 20 ไธชไบบ๏ผŒ่ฎกๆ•ฐ่ง„ๅˆ™ๆ˜ฏ [3, 5, 7, 13] ๅพช็Žฏใ€‚ๆœชๆฅๅฏ่ƒฝๆ”ฏๆŒ่‡ชๅฎšไน‰้…็ฝฎใ€‚

A: Current version is fixed at 20 people with [3, 5, 7, 13] counting pattern. Custom configuration may be supported in the future.

Q3: ไธบไป€ไนˆๆœ‰ไบ›ไปฃ็ ่กŒ็‚นๅ‡ปๅŽๆฒกๅๅบ”๏ผŸ / Why don't some code lines respond to clicks?

A: ้ƒจๅˆ†ไปฃ็ ่กŒ๏ผˆๅฆ‚ๆณจ้‡Š่กŒใ€ๅ‡ฝๆ•ฐๅฃฐๆ˜Ž๏ผ‰ไธๅฏนๅบ”ๅฎž้™…ๆ‰ง่กŒๆญฅ้ชค๏ผŒๅชๆœ‰ๅฎž้™…ๆ‰ง่กŒ็š„ไปฃ็ ่กŒๆ‰่ƒฝ่ทณ่ฝฌใ€‚

A: Some code lines (comments, function declarations) don't correspond to execution steps. Only actual execution lines are clickable.

Q4: ๅฏไปฅๅœจๆ‰‹ๆœบไธŠไฝฟ็”จๅ—๏ผŸ / Can I use it on mobile?

A: ๅฏไปฅ๏ผŒไฝ†ๆŽจ่ๅœจ็”ต่„‘ไธŠไฝฟ็”จไปฅ่Žทๅพ—ๆ›ดๅฅฝ็š„ไฝ“้ชŒใ€‚ๆ‰‹ๆœบๅฑๅน•่พƒๅฐ๏ผŒๅทฆๅณๅˆ†ๆ ๆ˜พ็คบไผšๆฏ”่พƒๆ‹ฅๆŒคใ€‚

A: Yes, but desktop is recommended for better experience. Mobile screens may feel cramped with the split-panel layout.

Q5: ๆƒณๅญฆไน ้กน็›ฎๆบ็ ๏ผŒไปŽๅ“ช้‡Œๅผ€ๅง‹๏ผŸ / Where to start learning the source code?

A: ๅปบ่ฎฎๆŒ‰ไปฅไธ‹้กบๅบ้˜…่ฏป / Recommended reading order:

  1. src/utils/josephus-simulator.js - ็ฎ—ๆณ•ๆจกๆ‹Ÿๅ™จๆ ธๅฟƒ้€ป่พ‘ / Algorithm simulator core logic
  2. src/App.vue - ไธปๅบ”็”จ็ป„ไปถ๏ผŒ็†่งฃๆ•ดไฝ“็ป“ๆž„ / Main application component to understand overall structure
  3. src/components/CircleAnimation.vue - ๅŠจ็”ปๆธฒๆŸ“้€ป่พ‘ / Animation rendering logic
  4. src/components/CodeDisplay.vue - ไปฃ็ ้ซ˜ไบฎๆ˜พ็คบ / Code highlighting display

๐Ÿค ่ดก็Œฎ / Contributing

ๆฌข่ฟŽๆไบค Issue ๅ’Œ Pull Request ๆฅๆ”น่ฟ›้กน็›ฎ๏ผ

Issues and Pull Requests are welcome to improve the project!

ๅผ€ๅ‘ๆŒ‡ๅ— / Development Guidelines

  • Git ๆไบคไฟกๆฏ้ตๅพช gitmoji ็บฆๅฎš / Git commit messages follow gitmoji convention
  • ไปฃ็ ้ฃŽๆ ผ้ตๅพช Vue 3 ๅฎ˜ๆ–นๆŽจ่ / Code style follows Vue 3 official recommendations
  • ๆไบคๅ‰่ฏท็กฎไฟไปฃ็ ้€š่ฟ‡ๆ‰€ๆœ‰ๆฃ€ๆŸฅ / Please ensure code passes all checks before submitting

ๆไบคไฟกๆฏๆ ผๅผ / Commit Message Format

:gitmoji: [type](scope): message

็คบไพ‹ / Examples:

โœจ feat(visualization): add new animation feature
๐Ÿ› fix(arrows): resolve arrow connection issues
๐Ÿ“ chore(docs): update README documentation

English

An interactive Josephus problem visualization tool built with Vue 3 + Vite, featuring line-by-line code debugging and animated demonstrations.

๐Ÿ’ก Project Value

Solving the pain point of beginners learning the Josephus problem: "understanding code but not logic"

Many students can understand each line of code when learning the Josephus problem, but cannot visualize the actual execution in their minds. This project uses a "left code + right debug-style animation" approach to help you:

  • ๐Ÿ‘€ Watch Code: Left side highlights the current execution line
  • ๐ŸŽฌ Visualize Process: Right side synchronously demonstrates linked list node movement and deletion
  • ๐Ÿ”— Make Connections: Real-time connection between code and animation makes understanding abstract logic easy

No installation required - just open the web page and start using it!

๐Ÿ“ธ Demo Screenshots

Live Demo: https://chhsiching.github.io/josephus-visualizer/

This project is deployed on GitHub Pages. Click the link above to see it in action. The interface includes:

  • Left Code Panel: Displays C code with current execution line highlighted
  • Right Animation Panel: Shows Josephus ring animation with node movement and elimination
  • Bottom Control Panel: Play, pause, step, and speed controls

โœจ Features

  • ๐ŸŽฏ Interactive Visualization: SVG-based circular linked list visualization with bidirectional pointers
  • ๐Ÿ“ Line-by-Line Debugging: GDB-style C code execution with real-time highlighting
  • โฏ๏ธ Complete Playback Controls: Play, pause, step execution, and speed adjustment
  • ๐Ÿ”„ Real-time Animation: Shows list construction, counting, and node elimination
  • ๐ŸŽจ Responsive Design: Gruvbox dark theme with screen size support
  • ๐Ÿ“Š Detailed Status Display: Shows current round, eliminated nodes, execution steps

๐Ÿš€ Quick Start

Live Demo

The project is deployed on GitHub Pages and can be accessed directly:

https://chhsiching.github.io/josephus-visualizer/

Local Development

# Clone the project
git clone https://github.com/chhsiching/josephus-visualizer.git
cd josephus-visualizer

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

๐Ÿ“– Algorithm Description

The Josephus Problem

The Josephus problem describes: n people stand in a circle, starting from a specified person and counting clockwise. The person who counts to k is eliminated, and the next person restarts counting from 1. This process continues until all people are eliminated, determining the elimination order.

Implementation Details

This project implements the Josephus problem using a doubly circular linked list:

  • Node Structure: Each person is represented as a node with id, next, and pre pointers
  • List Construction: RingConstruct function creates a doubly circular linked list with N nodes
  • Counting Pattern: Uses repeating pattern [3, 5, 7, 13] as elimination bounds for each round
  • Counting Function: count function starts from a node and counts to find the node to be eliminated
  • Node Removal: removeNode function removes the current node and reconnects the list

Visualization System

  • Dual-Ring Arrow System: Outer ring shows next pointers (clockwise), inner ring shows prev pointers (counter-clockwise)
  • Animation Phases: Initialization phase, counting phase, removal phase, completion phase
  • State Synchronization: Precise synchronization between code line numbers and animation states

๐ŸŽฎ Usage Instructions

Basic Operations

  1. Play/Pause: Click the play button to start automatic execution, click pause to stop
  2. Step Execution: Use forward/backward buttons to view algorithm execution step by step
  3. Speed Control: Supports 1x, 2x, 4x playback speeds
  4. Code Navigation: Click line numbers in the left code panel to jump to corresponding steps
  5. Reset: Click the reset button to restart the demonstration

Interface Description

  • Left Panel: Displays C code with current execution line highlighted
  • Right Panel: Circular visualization showing node states and pointer relationships
  • Bottom Control Bar: Playback controls, progress display, speed adjustment, etc.
  • Center Information: Shows current execution phase and round number

๐Ÿ› ๏ธ Tech Stack

  • Frontend Framework: Vue 3 (Composition API)
  • Build Tool: Vite
  • Styling: SCSS + Gruvbox dark theme
  • Syntax Highlighting: Shiki
  • Visualization: SVG
  • Deployment: GitHub Pages + GitHub Actions

๐Ÿ“ Project Structure

josephus-visualizer/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/          # Vue components
โ”‚   โ”‚   โ”œโ”€โ”€ App.vue         # Main application component
โ”‚   โ”‚   โ”œโ”€โ”€ CodeDisplay.vue # Code display component
โ”‚   โ”‚   โ”œโ”€โ”€ CircleAnimation.vue # Animation component
โ”‚   โ”‚   โ”œโ”€โ”€ ControlPanel.vue    # Control panel component
โ”‚   โ”‚   โ”œโ”€โ”€ CircleNode.vue     # Node component
โ”‚   โ”‚   โ””โ”€โ”€ CircleLink.vue     # Link component
โ”‚   โ”œโ”€โ”€ utils/               # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ josephus-simulator.js # Algorithm simulator
โ”‚   โ””โ”€โ”€ styles/              # Style files
โ”‚       โ””โ”€โ”€ gruvbox-dark.scss    # Theme styles
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ joseph-ring-algorithm.c # C algorithm source code
โ”œโ”€โ”€ .github/workflows/       # GitHub Actions configuration
โ”‚   โ””โ”€โ”€ deploy.yml         # Auto-deployment configuration
โ””โ”€โ”€ README.md

โš™๏ธ Configuration

  • Node Count: Fixed at 20 nodes
  • Counting Pattern: Repeating pattern [3, 5, 7, 13]
  • Animation Speed: Supports 1x, 2x, 4x speed adjustment
  • Theme Configuration: Gruvbox dark theme

๐Ÿ“„ License

This project is licensed under the MIT License.

โ“ FAQ

Q1: Animation stuck?

A: Refresh the page. If the issue persists, try reducing the playback speed (switch to 1x).

Q2: Can I change the number or counting rules?

A: Current version is fixed at 20 people with [3, 5, 7, 13] counting pattern. Custom configuration may be supported in the future.

Q3: Why don't some code lines respond to clicks?

A: Some code lines (comments, function declarations) don't correspond to actual execution steps. Only actual execution lines are clickable.

Q4: Can I use it on mobile?

A: Yes, but desktop is recommended for better experience. Mobile screens may feel cramped with the split-panel layout.

Q5: Where to start learning the source code?

A: Recommended reading order:

  1. src/utils/josephus-simulator.js - Algorithm simulator core logic
  2. src/App.vue - Main application component to understand overall structure
  3. src/components/CircleAnimation.vue - Animation rendering logic
  4. src/components/CodeDisplay.vue - Code highlighting display

๐Ÿค Contributing

Issues and Pull Requests are welcome to improve the project!

Development Guidelines

  • Git commit messages follow gitmoji convention
  • Code style follows Vue 3 official recommendations
  • Please ensure code passes all checks before submitting

Commit Message Format

:gitmoji: [type](scope): message

Examples:

โœจ feat(visualization): add new animation feature
๐Ÿ› fix(arrows): resolve arrow connection issues
๐Ÿ“ chore(docs): update README documentation

About

Interactive visualization of the Josephus problem using a circular linked list and C code animation.

Topics

Resources

License

Stars

Watchers

Forks

Contributors