#! /usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };my$SIZE=25*6;openmy$in,'<',shiftordie$!;my$min=$SIZE;my$result;while($SIZE==read$in,my$layer,$SIZE){my$zeros=$layer=~tr/0//;if($zeros<$min){my$ones=$layer=~tr/1//;my$twos=$layer=~tr/2//;$result=$ones*$twos;$min=$zeros;}}say$result;
Part 2
#! /usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };my$WIDTH=25;my$SIZE=$WIDTH*6;openmy$in,'<',shiftordie$!;my$result='2'x$SIZE;while($SIZE==read$in,my$layer,$SIZE){formy$i(0..$SIZE-1){my$front=substr$result,$i,1;nextif$front!=2;my$back=substr$layer,$i,1;substr$result,$i,1,$back;}}say$result=~s/.{$WIDTH}\K/\n/gr=~tr/01/ #/r;
Both solutions use the transliteration operator tr/// a lot. It's because it not only replaces characters one for one, but also returns the number of given characters in a string.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Using my native programming language, Perl:
Part 1
Part 2
Both solutions use the transliteration operator
tr///
a lot. It's because it not only replaces characters one for one, but also returns the number of given characters in a string.