From 563798871ad0e2888902bd5a4594cc77a3dbdc57 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sun, 9 Oct 2022 14:34:50 +0200 Subject: [PATCH] 2020 day 24 (bash) part 1: simplify code --- 2020/day24/ex1.bash | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/2020/day24/ex1.bash b/2020/day24/ex1.bash index 6155db2..e3842e9 100755 --- a/2020/day24/ex1.bash +++ b/2020/day24/ex1.bash @@ -27,21 +27,15 @@ while read -r line; do ;; esac if [[ "$c" = e ]]; then - (( x++ )) + ((++x)) elif [[ "$c" = w ]]; then - (( x-- )) + ((--x)) else printf "error c=%s\n" "$c" + exit 1 fi done - printf "new tile at (%d,%d): " "$x" "$y" - if [[ -v plan[$x,$y] ]]; then - printf "already set\n" - unset "plan[$x,$y]" - else - printf "new\n" - plan[$x,$y]=1 - fi + [[ -v plan[$x,$y] ]] && unset "plan[$x,$y]" || plan[$x,$y]=1 done res=${#plan[@]} printf "%s: res=%s\n" "$CMD" "$res"