Giter Club home page Giter Club logo

kenken-rs's Introduction

KenKen solver in Rust

This is a solver for KenKen puzzles, which are similar to Sudoku, but have cages of varying sizes whose cells must fulfill mathematical operations.

The solver employs a combined strategy of first reducing the candidates for each cage, and each cell in a cage, and then searching the solution using backtracking. Combined with Rust this makes it pretty fast.

Input files

There are several example puzzles in examples. The input format should be pretty obvious. Here is a small example:

abbc
a2cc
ddef
4def

a: 1-
b: 3-
c: 36*
d: 7+
e: 2/
f: 2/

The first part is a description of the cages (the puzzle size is taken from the first line). Each cage has a corresponding character - numbers are reserved for single-cell constant cages. In the second part, each cage is mapped to its arithmetic rule.

Puzzles are accepted up to size 15x15.

Building and running

Build and run using cargo run --release -- puzzle.ken [...]. This is the output for the above example puzzle:

Puzzle              Solution
┏━━━┳━━━┯━━━┳━━━┓   ┏━━━┳━━━┯━━━┳━━━┓
┃1- ┃3- │   ┃36×┃   ┃ 2 ┃ 4 │ 1 ┃ 3 ┃
┠───╊━━━╈━━━╃───┨   ┠───╊━━━╈━━━╃───┨
┃   ┃ 2 ┃   │   ┃   ┃ 1 ┃ 2 ┃ 3 │ 4 ┃
┣━━━╇━━━╋━━━╈━━━┫   ┣━━━╇━━━╋━━━╈━━━┫
┃7+ │   ┃2÷ ┃2÷ ┃   ┃ 3 │ 1 ┃ 4 ┃ 2 ┃
┣━━━╅───╂───╂───┨   ┣━━━╅───╂───╂───┨
┃ 4 ┃   ┃   ┃   ┃   ┃ 4 ┃ 3 ┃ 2 ┃ 1 ┃
┗━━━┻━━━┻━━━┻━━━┛   ┗━━━┻━━━┻━━━┻━━━┛
examples/test4.ken          8 steps     0.0985 ms

When multiple input files are given on the command line, the squares are not printed, only the filename, number of backtracking steps and timing.

kenken-rs's People

Contributors

birkenfeld avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.