-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3
6 lines (2 loc) · 807 Bytes
/
day3
1
2
3
4
5
line_lenght=$(head -1 input|wc -c);sideway=0;while read -r line ; do carpos=$(( sideway % (line_lenght -1) )); echo "result is ${line:$carpos:1}";sideway=$(($sideway +3)); done < ./input | grep "#"| wc -l
line_lenght=$(head -1 input|wc -c);slope_conf="1:1 1:3 1:5 1:7 2:1";result=1;for slope in $slope_conf; do echo "calculating $slope"; slopes=(${slope//:/ }); right_pos=0;trees=0;line_num=0;while read -r line ; do if (( line_num % ${slopes[0]} )) ;then line_num=$((line_num +1)); continue; fi ;car_pos=$(( $right_pos % ($line_lenght -1) )); echo -n "${line:$car_pos:1}"; if [[ "${line:$car_pos:1}" = "#" ]]; then trees=$((trees +1));fi;right_pos=$((right_pos + ${slopes[1]} )); line_num=$(( line_num +1)) ; done < ./input ; echo " $trees";result=$((result * trees)); done; echo "result is: $result"