Skip to main content
4 of 4
Trivial changes
nutki
  • 3.7k
  • 12
  • 12

Perl, 166 170 194

A perfect task for a language created by Larry Wall.

#!perl -pa $_=(1x($x=2/($y=pop@F)*map{1..$_}@F)." ")x$y;sub f{my$l=$_;$-|=!@_;for$=(@_){$Z=__ x~-$=;$f=0;s/(11){$=}/[$Z]/&!/\]..{$x}\[/s&&f(grep$=ne$_||$f++,@_);$-or$_=$l}}f@F 

Brute force, but quite fast on the test cases (<1s). Usage:

$ perl ~/wall.pl <<<"1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 5" [][__][__] [__][__][] [][__][__] [__][__][] [][__][__] 

Test me.

nutki
  • 3.7k
  • 12
  • 12