From e9ecb8b56098b11633bed3c39c85574a5f23be5b Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 4 May 2021 14:26:32 +0200 Subject: Bash solution for week 111, part 1 --- challenge-111/abigail/README.md | 1 + challenge-111/abigail/bash/ch-1.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 challenge-111/abigail/bash/ch-1.sh diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md index ce06c3891c..e78fafe291 100644 --- a/challenge-111/abigail/README.md +++ b/challenge-111/abigail/README.md @@ -32,6 +32,7 @@ languages, the fact input is sorted does not offer additional benefits. ### Solutions * [AWK](awk/ch-1.awk) +* [Bash](bash/ch-1.sh) * [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-111/abigail/bash/ch-1.sh b/challenge-111/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..0ef20b5732 --- /dev/null +++ b/challenge-111/abigail/bash/ch-1.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# + +declare -A matrix +MATRIX_SIZE=5 + +# +# Read in the matrix +# +for ((i = 1; i <= $MATRIX_SIZE; i ++)) +do read -a line + for n in ${line[@]} + do matrix[$n]=1 + done +done + +# +# Print 1/0 depending or not whether the number is in the matrix +# +while read number +do echo $((matrix[$number] ? 1 : 0)) +done -- cgit