Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>original reply</strong></p> <p>do you have to write all the code yourself or are you interested in exploring other tools? because i would suggest looking at constraint propagation / linear programming. you already have a lot of boundary constraints - that the outer edges cannot have pipes, plus the inner edges - so i imagine this will work quite efficiently. also, the constraints look like they will be simple equalities, so it should be pretty easy to set up.</p> <p>i don't have enough experience with this to give more details here (although if i have time in the next week i may give it a go at some point), but if this kind of thing is interesting there's a bit more background in <a href="https://stackoverflow.com/a/7237972/181772">another answer i wrote some time ago</a>.</p> <p>ps interesting question; thanks for posting this.</p> <p>[edit: if you cannot use other libraries then you can do the constraint propagation yourself. there's a wonderful <a href="http://norvig.com/sudoku.html" rel="nofollow noreferrer">article by norvig</a> that shows how to do this for sudoku. i would strongly suggest reading that - i think you will see how to carry the techniques across, even though it's sudoku and python.]</p> <p><strong>updated reply</strong> (2012-04-06 - updated with blog references; old comments were buggy)</p> <p>a depth-first search, where the next empty cell is filled with each available, <em>consistent</em> tile, and the consistency check includes both edge constraints (no pipes off the edge) and nearest neighbours, is quite efficient.  i have an unoptimized implementation in clojure that will solve the smaller example in around 0.4ms (1000 in 360ms after JVM warmup) and the larger in 3ms (cedric van goethem reports 1ms for an optimised - but still OO - java implementation, which seems reasonable).  it can solve a 10x10 puzzle (concentric circles of tubes with no initial hints) in 12s.</p> <p>i also spent time looking at a "smart" approach, which tracks constraints on each cell, much like in norvig's paper above. and then i tried using <a href="http://www.emn.fr/z-info/choco-solver/" rel="nofollow noreferrer">choco</a>. all this is described in much more detail in <a href="http://isti.bitbucket.org" rel="nofollow noreferrer">blog posts here</a> (i did have more details in an update to this answer, but they were based on buggy code - the blog has more, better information). the source is also available for download.</p> <p>the general conclusion from all this was that direct search is fine up to 10x10. after that, more smarts may help, but it's difficult to be sure because generating test cases is hard (they tend to be ambiguous, even when lots of cells are given).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload