axelrose has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to solve a special sorting task with Perl and wonder if this is a standard computer science problem.
Say I have three slots 1..3 and an empty slot 0
slot 1 => cslot 2 => a
slot 3 => b
slot 0 => 0
The slots hold a labeled object (it's a tape library with magazine slots)
The goal is
slot 1 => aslot 2 => b
slot 3 => c
and a list of move actions where ideally the number of moves is minimal.
A pragmatic solution is for instance
move( 1, 0 ); # ( 0, a, b, c )move( 2, 1 ); # ( a, 0, b, c )
move( 3, 2 ); # ( a, b, 0, c )
move( 0, 3 ); # goal order achieved
where the function move( <from-slot>, <to-slot> ) moves an object from one slot to a different slot.
The question is not so much how to implement this in Perl but whether there exists an known algorithm. Of course I'm happy to post a Perl solution here.
Many thanks, Axel.
Back to
Seekers of Perl Wisdom