Nonoblock: Difference between revisions

m (added highlighting and whitespace to the task's preamble.)
Line 1,231:
Nonoblock 5,2,3,2
</lang>
 
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl
 
use strict; # http://www.rosettacode.org/wiki/Nonoblock
use warnings;
 
while( <DATA> )
{
print "\n$_", tr/\n/=/cr;
my ($cells, @blocks) = split;
my $letter = 'A';
$_ = join '.', map $letter++ x $_, @blocks;
$cells < length and print("no solution\n"), next;
$_ .= '.' x ($cells - length) . "\n";
1 while print, s/^(\.*)\b(.*?)\b(\w+)\.\B/$2$1.$3/;
}
 
__DATA__
5 2 1
5
10 8
15 2 3 2 3
5 2 3</lang>
{{out}}
<pre>
5 2 1
=====
AA.B.
AA..B
.AA.B
 
5
=
.....
 
10 8
====
AAAAAAAA..
.AAAAAAAA.
..AAAAAAAA
 
15 2 3 2 3
==========
AA.BBB.CC.DDD..
AA.BBB.CC..DDD.
AA.BBB..CC.DDD.
AA..BBB.CC.DDD.
.AA.BBB.CC.DDD.
AA.BBB.CC...DDD
AA.BBB..CC..DDD
AA..BBB.CC..DDD
.AA.BBB.CC..DDD
AA.BBB...CC.DDD
AA..BBB..CC.DDD
.AA.BBB..CC.DDD
AA...BBB.CC.DDD
.AA..BBB.CC.DDD
..AA.BBB.CC.DDD
 
5 2 3
=====
no solution
 
</pre>
 
=={{header|Phix}}==
Anonymous user