I just typed up a nice algorithm here (which was essentially brute force) when I thought of a much better one. Damn. This one should be better, and you can apply it in real life as well.

  1. Begin by placing 7->8 "marker" pieces of track at various points around the floor. Make sure they're spaced well apart from each other.
  2. For each marker track that you haven't already used:
    1. Find the marker track nearest to it.
    2. Lay track down in such a pattern that it joins the two marker tracks together.
  3. Put some trains on it and make "choo choo!" noises.

This seems boring, but it's much, much faster than trying a brute-force method, and it still produces interesting tracks.

One of the interesting things (that I just thought of) about this design is the pathfinding - if you're laying down a track, but there's another piece of track in the way, don't remove the bit of track, but use one of the circle pieces to divert it around that bit of track. This makes the rails run together, as rails tend to do!

If you're really looking for a challenge, try making the algorithm recursive by using it again while doing step 2.2. And well done for thinking of such an interesting puzzle!


~abseed

In reply to Re: Closed geometry: a train track problem by abcde
in thread Closed geometry: a train track problem by SamCG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.