|Do you know where your variables are?|
sort with fewest movesby axelrose (Scribe)
|on Feb 10, 2002 at 16:06 UTC||Need Help??|
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 0slot 1 => c
slot 2 => a
slot 3 => b
slot 0 => 0
The slots hold a labeled object (it's a tape library with magazine slots)
The goal isslot 1 => a
slot 2 => b
slot 3 => c
and a list of move actions where ideally the number of moves is minimal.
A pragmatic solution is for instancemove( 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.