-
-
Save rhowe/8dec58098bb1d263ac908e4d398e879b to your computer and use it in GitHub Desktop.
AOC2019day8part1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
input=$(<"$1") | |
layers=() | |
width=25 | |
height=6 | |
area=$((width * height)) | |
for offset in $(seq 0 "$area" "${#input}"); do | |
layers+=("${input:$offset:$area}") | |
done | |
bestlayer=0 | |
bestlayer_nonzeros=0 | |
for layer in "${layers[@]}"; do | |
nonzeros=${layer//0/} | |
if [ "${#nonzeros}" -gt "$bestlayer_nonzeros" ]; then | |
bestlayer=$layer | |
bestlayer_nonzeros=${#nonzeros} | |
fi | |
done | |
ones=$(tr -dc 1 <<<"$bestlayer") | |
twos=$(tr -dc 2 <<<"$bestlayer") | |
echo $(( ${#ones} * ${#twos})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment