fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4. use List::Util qw(shuffle);
  5.  
  6. sub _f { [shuffle(('0') x ($_[0] - $_[1]), ('*') x $_[1])] }
  7.  
  8. sub f { map{ _f($_[0], int rand($_[0] * 0.4)) } (0 .. $_[1]) }
  9.  
  10.  
  11. sub bomb { $_[0] eq '*' ? 1 : 0 }
  12.  
  13. sub __g {
  14. my @l = (0, @_, 0);
  15.  
  16. bomb($l[$_ + 1]) ? '*' : $l[$_+ 1] + bomb($l[$_]) + bomb($l[$_ + 2])
  17. } (0 .. $#l - 2)
  18. }
  19.  
  20. sub _g { map{ [__g(@{$_})] } @_ }
  21.  
  22. sub turn {
  23. map{ my $x = $_; [map{ $_[$_]->[$x] } (0 .. $#_)] } (0 .. $#{$_[0]})
  24. }
  25.  
  26. sub g { turn _g(turn _g(@_)) }
  27.  
  28.  
  29. sub d { join '', map{ (ref() ? (d(@{$_}) . "\n") : $_) } @_ }
  30.  
  31. say d (my @map = f(10, 10));
  32. say d g(@map);
  33.  
Success #stdin #stdout 0s 3892KB
stdin
Standard input is empty
stdout
**000000*0
0000000000
0000000000
000*00*00*
00*0000000
0000000000
0*0*000000
000000000*
00*0*00000
00000*0000
000*000000

**100001*1
1100000010
0001001001
002*11*11*
01*2001001
0111000000
1*2*100001
011110001*
01*2*20001
00112*1000
001*110000