Skip to content

Latest commit

 

History

History
107 lines (84 loc) · 3.96 KB

README.md

File metadata and controls

107 lines (84 loc) · 3.96 KB

Web K-Map Solver

A lightweight Karnaugh map solver implemented in pure HTML5, CSS3, and minimal JavaScript. This tool helps simplify Boolean algebraic expressions using the K-map method, always providing results in Sum of Products (SOP) format.

What is a Karnaugh Map?

A Karnaugh map (K-map) is a method to simplify Boolean algebra expressions. It provides a visual way to minimize Boolean functions to their simplest form, which is essential in digital logic design and circuit optimization. The map arranges Boolean variables in a grid where adjacent cells differ by only one bit (Gray code order).

Variables and Notation

The K-map supports 2-4 variables, which can be selected via the variable selector:

  • 2 variables: A, B (2×2 grid)
  • 3 variables: A, B, C (2×4 grid)
  • 4 variables: A, B, C, D (4×4 grid)

Variables are arranged in Gray code order (where adjacent values differ by only one bit).

Variable notation in solutions:

  • Regular letter (A): Variable is 1 (TRUE)
  • Letter with prime (A'): Variable is 0 (FALSE)
  • Example: A'BC'D = A=0, B=1, C=0, D=1

Features

  • Interactive K-Map interface with variable selection (2-4 variables)
  • Two layout options:
    • Gray code layout (optimal for adjacency)
    • Normal binary layout (available for 3-4 variables)
  • Visual cell grouping with wraparound support
  • Auto-solving with Boolean algebra simplification
  • Results always in minimal SOP (Sum of Products) format
  • Support for don't care conditions (X)
  • Multiple solution display when available
  • One-click copy solution to clipboard
  • Synchronized Truth Table view
  • Enhanced info guide with usage examples
  • Modern, clean UI with:
    • Vector icons
    • Organized action bar for controls
    • Light/Dark/Auto theme support
    • System theme detection
  • Quick operations:
    • Set all cells to 1
    • Set all cells to 0
    • Clear the map
    • Copy solution
  • Triple-state cells:
    • 0 (false)
    • 1 (true)
    • X (don't care)
  • Responsive design for mobile and desktop
  • Offline support:
    • Works without internet after first visit
    • Fast loading with cached resources

How to Use

  1. Select the number of variables (2-4) using the variable selector
  2. Click on cells to cycle through values:
    • 0 → 1 → X (don't care) → 0
  3. The solution updates automatically in SOP format
  4. Click the copy icon to copy the result
  5. Use "All 1" or "All 0" buttons for quick setup
  6. Use "Clear" to reset the map
  7. Switch between K-map and Truth Table views
  8. Use the layout toggle to switch between Gray code and normal layouts (3-4 variables only)
  9. Click the info icon for the usage guide

Technical Details

  • Built with vanilla HTML5, CSS3, and JavaScript
  • No external dependencies
  • Boolean algebra simplification using Quine-McCluskey algorithm
  • Gray code implementation for optimal cell adjacency
  • Real-time synchronization between K-map and Truth Table
  • Vector-based UI elements for crisp display
  • Responsive layout with CSS Grid and Flexbox
  • Mobile-first design principles
  • Theme system:
    • Light and Dark themes with Auto detection
    • CSS variables for consistent styling
    • Persistent theme preferences
    • Optimized for readability across all K-map sizes

Implementation Notes

The solver uses the following process:

  1. Identifies prime implicants using the Quine-McCluskey algorithm
  2. Finds essential prime implicants
  3. Solves the covering problem for remaining implicants
  4. Simplifies the expression using Boolean algebra
  5. Presents the result in minimal SOP format

TODO:

Credits

Created by robonxt.

Assisted by Claude Sonnet 3.5 in Windsurf IDE.

Logic inspired by https://github.com/obsfx/kmap-solver-lib

Icon generated by Perchance