Giter Site home page Giter Site logo

scala-99-problems's Introduction

Solution of the Problem 99 from http://aperiodic.net/phil/scala/s-99/

The algorithm is backtracking with a simple observation:
- for some segments, there is only one option (one word of suitable length) -> place it immediately
- when there are more options, try the segments with least options first

Such heuristic is enough for the algorithm to solve the sample problems almost without backtracking.
Try running "crosswordsolver input/p99d.dat -debug" to see the progress of the algorithm.

There are quite a few opportunities for optimization (searching more branches in parallel would be fun!), 
but even this solves all the sample problems under 60ms on my laptop.

Overview:

The representation of the crossword is the following:

- Each 'dot' in the crossword is represented by one Cell.
- Each line to put a word in is represented by a Segment.
- A Segment has Intersections which tell with which other Segments it intersects (useful for Solver).
- Crossword is:
  - a collection of Segments
  - a collection of input words
  - a 2d matrix of Cells holding the layout of the crossword (for printing)

Loader builds the Crossword from the input file.
Solver gets an empty crossword and returns a Solution containing filled crossword, or None if there is no solution.

scala-99-problems's People

Contributors

mkonicek avatar

Stargazers

 avatar Chan Nguyen avatar Pavel avatar  avatar Stone Gao avatar

Watchers

 avatar James Cloos 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.