2020/23 bash: unify the 2 parts code
This commit is contained in:
@@ -6,7 +6,7 @@ CMD=${0##*/}
|
|||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
set -o noglob
|
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
|
declare -i end runs cup _cup
|
||||||
|
|
||||||
read -r str
|
read -r str
|
||||||
@@ -27,9 +27,8 @@ done
|
|||||||
next[$_cup]=$cup # close the ring
|
next[$_cup]=$cup # close the ring
|
||||||
|
|
||||||
_cup=$cup
|
_cup=$cup
|
||||||
|
|
||||||
declare -i _1st _2nd _3rd dest
|
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
|
for ((i = 1; i <= runs; ++i)); do
|
||||||
_1st="${next[$cup]}"
|
_1st="${next[$cup]}"
|
||||||
_2nd="${next[$_1st]}"
|
_2nd="${next[$_1st]}"
|
||||||
|
@@ -33,6 +33,7 @@ next[$_cup]=$cup # close the ring
|
|||||||
|
|
||||||
_cup=$cup
|
_cup=$cup
|
||||||
declare -i _1st _2nd _3rd dest
|
declare -i _1st _2nd _3rd dest
|
||||||
|
# make the moves: a simple sub linked list operation.
|
||||||
for ((i = 1; i <= runs; ++i)); do
|
for ((i = 1; i <= runs; ++i)); do
|
||||||
_1st="${next[$cup]}"
|
_1st="${next[$cup]}"
|
||||||
_2nd="${next[$_1st]}"
|
_2nd="${next[$_1st]}"
|
||||||
|
Reference in New Issue
Block a user