Advertisement
musifter

Untitled

Dec 8th, 2019
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.91 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use constant SIZE_X => 25;
  7. use constant SIZE_Y => 6;
  8. use constant LAYER_SIZE => 150;
  9.  
  10. # 0 - black
  11. # 1 - white
  12. # 2 - transparent (shouldn't happen: let it throw, let it throw, let it throw!)
  13. my @CHARS = (' ', '#');
  14.  
  15. my @data = map { chomp; split( // ) } <>;
  16.  
  17. my @layers;
  18. while (@data) {
  19.     push( @layers, [ splice( @data, 0, LAYER_SIZE ) ] );
  20. }
  21.  
  22. my $min = LAYER_SIZE + 1;
  23. my $ret = 0;
  24. my @output;
  25.  
  26. foreach my $layer (@layers) {
  27.     my @counts = (0, 0, 0);
  28.     foreach my $i (0 .. LAYER_SIZE - 1) {
  29.         $counts[$layer->[$i]]++;
  30.         $output[$i] //= $CHARS[$layer->[$i]] if ($layer->[$i] != 2);
  31.     }
  32.  
  33.     if ($counts[0] < $min) {
  34.         $min = $counts[0];
  35.         $ret = $counts[1] * $counts[2];
  36.     }
  37. }
  38.  
  39. print "#ones * #twos on minimal zero layer: $ret\n\n";
  40.  
  41. foreach my $line (1 .. SIZE_Y) {
  42.     print splice( @output, 0, SIZE_X ), "\n";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement