#!/usr/bin/perl # http://perlmonks.org/?node_id=1207779 use strict; use warnings; print local $_ = my $grid = < keys %{{ map +($_, $_), shift =~ /\w/g }} } while( /[A-Z]/g ) # mark square to '-' if tree there causes a missing color { missingcolor( lc clear( "$`\l$&$'" ) ) and $_ = "$`-$'", print $_, ' ' x $N, " mark ", $-[0] % ($N + 1), ',', int $-[0] / ($N + 1), "\n"; # x,y coords } print s/[A-Z]/$&/g == $N ? "\nSolved!\n" : "Failed\n";