Finally somthing which doesn't involve with opcode :P
Solution in swift
importCocoaletwidth=25lettall=6letdigits=input.compactMap{Int(String($0))}letnumberOfLayer=digits.count/(width*tall)varstartIndex=0letlayers=(1...numberOfLayer).map{layerNumber->Array<Int>inletcount=(width*tall)*layerNumberletlayer=digits[startIndex..<count]startIndex=countreturnArray(layer)}funcpartTwo(){varresult:[Int]=Array.init(repeating:0,count:width*tall)letfirst=layers.first!for(index,value)infirst.enumerated(){ifvalue==0||value==1{result[index]=value}else{forlayerinlayers.dropFirst(){if(layer[index]==0||layer[index]==1){result[index]=layer[index]break}}}}startIndex=0whiletrue{letcount=width+startIndexletvalue=result[startIndex..<count]startIndex=countprint(value)ifstartIndex>=result.count{break}}}funcpartOne(){varlow:[Int]=[]varlowestCount:Int=Int.maxforlayerinlayers{letdict=layer.reduce(into:[:]){counts,numberincounts[number,default:0]+=1}letcount=dict[0]ifletcount=count{ifcount<lowestCount{lowestCount=countlow=layer}}}letdict=low.reduce(into:[:]){counts,numberincounts[number,default:0]+=1}letresult=(dict[1]??0)*(dict[2]??0)print("Result is : \(result)")}partOne()partTwo()
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.
Finally somthing which doesn't involve with opcode :P
Solution in swift