33 lines
740 B
Bash
Executable File
33 lines
740 B
Bash
Executable File
#!/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
|