Aw yeah something simple again! Maybe even a little bit too simple? ð
Anyway, in JavaScript:
constWIDTH=25;constHEIGHT=6;constlayerSize=WIDTH*HEIGHT;constlayers=input.match(newRegExp(`[012]{${layerSize}}`,'g'));// Part Onefunctioncount(string,needle){returnstring.split(needle).length-1;}constdigitCounts=[0,1,2].map(digit=>layers.map(layer=>count(layer,digit)));constminZeros=Math.min(...digitCounts[0]);constminZeroLayerIndex=digitCounts[0].indexOf(minZeros);console.log(digitCounts[1][minZeroLayerIndex]*digitCounts[2][minZeroLayerIndex]);// Part Twoconstcomposed=Array.from({length:layerSize},(_,index)=>{returnlayers.find(layer=>layer[index]!=='2')[index];});// Pretty print the output ðĪŠconsole.log(composed.join('').replace(/0/g,'').replace(/1/g,'#').match(newRegExp(`[012]{${WIDTH}}`,'g')).join('\n'));
Aw yeah something simple again! Maybe even a little bit too simple? ð
Anyway, in JavaScript:
Check my repo for my input.
By the way, here's the language count for day 7 (it could be subject to change as it was a kind of complex challenge):
JavaScript à 3
Python à 2
C Ã 1
Clojure à 1
Java à 1
Swift à 1