From f6d1fe7b9d8d8ac82d194367a04892e629c9bc94 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Thu, 20 Oct 2022 08:51:10 +0200 Subject: [PATCH] 2020/23 bash: unify the 2 parts code --- 2020/day23/ex1.bash | 5 ++--- 2020/day23/ex2.bash | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/2020/day23/ex1.bash b/2020/day23/ex1.bash index 742f0c8..e1635a5 100755 --- a/2020/day23/ex1.bash +++ b/2020/day23/ex1.bash @@ -6,7 +6,7 @@ CMD=${0##*/} shopt -s extglob set -o noglob -declare -A next # next[i] is cup right to i +declare -A next # next[i] is cup right to i (ring) declare -i end runs cup _cup read -r str @@ -27,9 +27,8 @@ done next[$_cup]=$cup # close the ring _cup=$cup - declare -i _1st _2nd _3rd dest -# make the moves: a simple sub-linked list operation. +# make the moves: a simple sub linked list operation. for ((i = 1; i <= runs; ++i)); do _1st="${next[$cup]}" _2nd="${next[$_1st]}" diff --git a/2020/day23/ex2.bash b/2020/day23/ex2.bash index 5fee486..e9d92e6 100755 --- a/2020/day23/ex2.bash +++ b/2020/day23/ex2.bash @@ -33,6 +33,7 @@ next[$_cup]=$cup # close the ring _cup=$cup declare -i _1st _2nd _3rd dest +# make the moves: a simple sub linked list operation. for ((i = 1; i <= runs; ++i)); do _1st="${next[$cup]}" _2nd="${next[$_1st]}"