X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2021.git/blobdiff_plain/64d8769ea65405cdc0a1f8e65a8a1fa25bbf71df..9211cd2ef3bbf35f1328c86c5c6290005c014cb3:/day06/lanternfish2.sh diff --git a/day06/lanternfish2.sh b/day06/lanternfish2.sh deleted file mode 100755 index 924ac46..0000000 --- a/day06/lanternfish2.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -set -u -set -e - -declare -a fish - -filename="${1:-example.txt}" - -exec 3<"$filename" - -OLDIFS="$IFS" -IFS="," -read -u 3 -a fish -IFS="$OLDIFS" - -buckets=(0 0 0 0 0 0 0 0 0) - -for f in "${fish[@]}"; do - ((buckets[$f]+=1)) -done - -for (( d=1; d<=256; d++ )); do - orig_zeros=${buckets[0]} - for (( i=1; i<=8; i++ )); do - temp=${buckets[$i]} - ((buckets[$((i-1))]+=$temp)) || true - buckets[$i]=0 - done - ((buckets[8]+=$orig_zeros)) || true - ((buckets[6]+=$orig_zeros)) || true - ((buckets[0]-=$orig_zeros)) || buckets[0]=0 -done - -count=0 -for (( i=0; i<=8; i++ )); do - ((count+=${buckets[$i]})) -done - -echo "After 256 days there are $count fish"