Day 13 added, bash & C.

This commit is contained in:
2020-12-21 19:26:10 +01:00
parent 11844d1904
commit 55fc1b8576
11 changed files with 332 additions and 1 deletions

32
day13/ex2.bash Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
#
# ex1.bash: Advent2020 game, day 13/game 2.
CMD=${0##*/}
shopt -s extglob
declare -a buses btimes
declare -i lcm=1 thetime=0 c=0 t=0
read -r line
read -r line
IFS=,
for i in ${line}; do
if [[ $i != x ]]; then
buses[$c]=$i
btimes[$c]=$t
((c++))
fi
((t++))
done
for ((i=0; i<(${#buses[@]}-1); ++i)); do
bus=${buses[i+1]}
idx=${btimes[i+1]}
((lcm*=buses[i]))
while ((((thetime + idx) % bus) != 0)); do
((thetime+=lcm))
done
done
printf "%s : res=%d\n" "$CMD" "$thetime"
exit 0