#!/usr/bin/perl
use 5.016;
use warnings;
use List
::Util qw(shuffle
);
sub _f { [shuffle(('0') x ($_[0] - $_[1]), ('*') x $_[1])] }
sub f
{ map{ _f
($_[0], int rand($_[0] * 0.4)) } (0 .. $_[1]) }
sub bomb { $_[0] eq '*' ? 1 : 0 }
sub __g {
my @l = (0, @_, 0);
bomb($l[$_ + 1]) ? '*' : $l[$_+ 1] + bomb($l[$_]) + bomb($l[$_ + 2])
} (0 .. $#l - 2)
}
sub _g
{ map{ [__g
(@{$_})] } @_ }
sub turn {
map{ my $x = $_; [map{ $_[$_]->[$x] } (0 .. $#_)] } (0 .. $#{$_[0]}) }
sub g { turn _g(turn _g(@_)) }
sub d
{ join '', map{ (ref() ? (d
(@{$_}) . "\n") : $_) } @_ }
say d
(my @map = f
(10, 10));
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwp1c2UgTGlzdDo6VXRpbCBxdyhzaHVmZmxlKTsKCnN1YiBfZiB7IFtzaHVmZmxlKCgnMCcpIHggKCRfWzBdIC0gJF9bMV0pLCAoJyonKSB4ICRfWzFdKV0gfQoKc3ViIGYgeyBtYXB7IF9mKCRfWzBdLCBpbnQgcmFuZCgkX1swXSAqIDAuNCkpIH0gKDAgLi4gJF9bMV0pIH0KCgpzdWIgYm9tYiB7ICRfWzBdIGVxICcqJyA/IDEgOiAwIH0KCnN1YiBfX2cgewoJbXkgQGwgPSAoMCwgQF8sIDApOwoKCXJldHVybiBtYXB7CgkJYm9tYigkbFskXyArIDFdKSA/ICcqJyA6ICRsWyRfKyAxXSArIGJvbWIoJGxbJF9dKSArIGJvbWIoJGxbJF8gKyAyXSkKCX0gKDAgLi4gJCNsIC0gMikKfQoKc3ViIF9nIHsgbWFweyBbX19nKEB7JF99KV0gfSBAXyB9CgpzdWIgdHVybiB7CgltYXB7IG15ICR4ID0gJF87IFttYXB7ICRfWyRfXS0+WyR4XSB9ICgwIC4uICQjXyldIH0gKDAgLi4gJCN7JF9bMF19KQp9CgpzdWIgZyB7IHR1cm4gX2codHVybiBfZyhAXykpIH0KCgpzdWIgZCB7IGpvaW4gJycsIG1hcHsgKHJlZigpID8gKGQoQHskX30pIC4gIlxuIikgOiAkXykgfSBAXyB9CgpzYXkgZCAobXkgQG1hcCA9IGYoMTAsIDEwKSk7CnNheSBkIGcoQG1hcCk7Cg==