Created
December 3, 2020 17:12
-
-
Save mattk42/a271d50c54153024f6e3d32fd4f9c597 to your computer and use it in GitHub Desktop.
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 | |
pos=1 | |
line_num=0 | |
trees=0 | |
while read line | |
do | |
len=$(echo $line | wc -c) | |
char_at_pos=$(echo $line | cut -c $pos) | |
# Calculate next pos | |
pos=$(($pos + 3)) | |
if [ $pos -ge $len ] | |
then | |
pos=$((($pos % $len) + 1)) | |
fi | |
# Don't count the first line | |
if [ $line_num -gt 0 ] | |
then | |
if [ $char_at_pos != "." ] | |
then | |
trees=$(($trees + 1)) | |
fi | |
fi | |
line_num=$(($line_num + 1)) | |
done <<< $(< $1) | |
echo $trees |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment