fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4.  
  5. sub repeat {
  6. my ($n, $f) = @_;
  7.  
  8. return sub{ ($f->($_[0])) x $n };
  9. }
  10.  
  11. sub repeat_alt {
  12. my ($s, $n, $f) = @_;
  13.  
  14. return sub{ join($s, map{ $f->($_[0] + $_) } (0 .. $n - 1)) };
  15. }
  16.  
  17. sub f {
  18. my ($m, $n) = @_;
  19.  
  20. my $marker = sub{ $_[0] % 2 ? 'x' : 'o' };
  21. my $f = repeat_alt("", $n, repeat($m, $marker));
  22. my $g = repeat_alt("\n", $n, repeat($m, $f));
  23.  
  24. return ($n == 1 ? $f : $g)->(0);
  25. }
  26.  
  27. while(<STDIN>){
  28. my ($m, $n) = split;
  29.  
  30. print "$m $n\n", f($m, $n), "\n\n";
  31. }
  32.  
Success #stdin #stdout 0s 3736KB
stdin
3 2
2 3
1 1
2 1
stdout
3 2
oooxxx
oooxxx
oooxxx
xxxooo
xxxooo
xxxooo

2 3
ooxxoo
ooxxoo
xxooxx
xxooxx
ooxxoo
ooxxoo

1 1
o

2 1
oo