This commit is contained in:
2021-12-21 14:47:09 +01:00
parent 467f8f499a
commit bdd1421637
2 changed files with 145 additions and 0 deletions

32
21/01.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
positions=()
scores=()
while read line; do
positions+=( $(sed 's/^.* \([0-9]*\)$/\1/' <<< $line) )
scores+=( 0 )
done
dice_next_value=1
player_index=0
finished=0
n_rolls=0
while [ $finished -eq 0 ]; do
roll=$((dice_next_value+dice_next_value+1+(dice_next_value+1)%100+1))
dice_next_value=$(((dice_next_value+2)%100+1))
positions[$player_index]=$(((positions[player_index]+roll-1)%10+1))
scores[$player_index]=$((scores[player_index]+positions[player_index]))
if [ ${scores[$player_index]} -ge 1000 ]; then
finished=1
fi
player_index=$(((player_index+1)%${#positions[@]}))
n_rolls=$((n_rolls+3))
done
for score in ${scores[@]}; do
if [ $score -lt 1000 ]; then
echo $((score*n_rolls))
fi
done