JanetRossini.github.io

Lua, LSL, Blender, Python in Second Life


Project maintained by JanetRossini

Shunting: Cracked!

May 7, 2025 • [designluashunting]


There is a crack, a crack in everything. That’s how the light gets in.
– Leonard Cohen

I think I’ve got it cracked! Not optimally, mind you, but I think I see enough to be able to solve any train, perhaps sub-optimally. Here’s what has happened since we were last together here:

With that in hand, it seems to me that it will be “easy” to take any given arrangement, stash the blanks as described above, then reduce the inversions in the remaining train one at a time until done. Maybe there is a faster way, but yesterday I had no solutions and today I nearly have one. Zero to one way is a big step. Sometime impossible yesterday is possible today.

If I’m right. But I’m confident that I am. I could be wrong. As one of my heroes often says, “I frequently am”, but I think this is not one of those times.

And now?

Good question. I am not sure, but I think next steps might include:

  1. Write an SLua program, with tests, to demonstrate that the basic idea of the solution works. Limit to a five car train with no blanks.
  2. Enhance that program, or write a new one, that shows the train moves for the inversions, so that I can see that the locomotive can perform all the necessary actions. I’m confident, but might like to test this in code.
  3. Build a small model of the situation that creates a random order and then moves the pieces around, following the algorithm.

Somewhere along there, perhaps last, start breaking the train into two pieces, including the blanks, and build up the part that moves the situation to the canonical position: numbered cars in the 5-shunt, 1 blank in one 3-shunt and 2 blanks in the other. Put that code at the beginning and the problem is solved.

The basic idea of the program will be that there will be four “primitive” moving operations defined: Swap12, Swap23, Swap34, and Swap45. Then we’ll “just” scan the train from left to right, looking for inversions and when we find them, swap them. Repeat until there are no more. Declare victory.

You call that a design?

Well, no. I call that a design idea, I guess, or a random pile of design ideas. But they are enough to get me started, and yesterday I was stopped. But yes, plenty needs to be figured out. Questions that I can see include:

And big questions:

Next steps?

Right now, nothing. I think I’ll read my dragon fantasy romance book for a bit. But next steps beyond that will be some SLua code.

Safe paths!