Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use constant SIZE_X => 25;
- use constant SIZE_Y => 6;
- use constant LAYER_SIZE => 150;
- # 0 - black
- # 1 - white
- # 2 - transparent (shouldn't happen: let it throw, let it throw, let it throw!)
- my @CHARS = (' ', '#');
- my @data = map { chomp; split( // ) } <>;
- my @layers;
- while (@data) {
- push( @layers, [ splice( @data, 0, LAYER_SIZE ) ] );
- }
- my $min = LAYER_SIZE + 1;
- my $ret = 0;
- my @output;
- foreach my $layer (@layers) {
- my @counts = (0, 0, 0);
- foreach my $i (0 .. LAYER_SIZE - 1) {
- $counts[$layer->[$i]]++;
- $output[$i] //= $CHARS[$layer->[$i]] if ($layer->[$i] != 2);
- }
- if ($counts[0] < $min) {
- $min = $counts[0];
- $ret = $counts[1] * $counts[2];
- }
- }
- print "#ones * #twos on minimal zero layer: $ret\n\n";
- foreach my $line (1 .. SIZE_Y) {
- print splice( @output, 0, SIZE_X ), "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement