Extendable Train Swapping Problem
Perl, 120 bytes

Includes +6 for -Xapi (- and space are counted too because both the -i and the $' in the code make it impossible to combine the options with -e)

Run with the input on STDIN and the platform length after the -i option, e.g.

perl -Xapi3 trains.pl &lt;&lt;&lt; "1 4 5 6 3 8 7 2 9"


Prints -2 if there is no solution

trains.pl:

1until$_=$n++*$z{pack"W*",@F}||-!grep!$z{$_}++&amp;&amp;/.{$^I}(??{!\$z{$`.reverse($&amp;).$'}})$/s,keys%z,pack"W*",1..@F;$_--


if N &lt;= 9 then you can gain 5 more bytes:

1until$_=$n++*$z{join"",@F}||-!grep!$z{$_}++&amp;&amp;/.{$^I}(??{!\$z{$`.reverse($&amp;).$'}})$/,keys%z,join"",1..@F;$_--