Skip to content

Instantly share code, notes, and snippets.

@azuddin
Last active August 27, 2021 17:57
Show Gist options
  • Save azuddin/0030dfcf29b47d94fcc61a87f41cce8d to your computer and use it in GitHub Desktop.
Save azuddin/0030dfcf29b47d94fcc61a87f41cce8d to your computer and use it in GitHub Desktop.
helping member for his assignment
#!/bin/bash
clear
echo
# getting 1st argument
echo "Please enter an series of numbers. e.g: 1 2 4 7 11 15"
read firstParam
# sanitised1stParam="${firstParam// /}"
# getting 2nd argument
echo
echo "Next please enter a digit. e.g: 15 "
read secondParam
sanitised2ndParam="${secondParam// /}"
echo
sum=0
notFound=true
# calculate
array=( $firstParam )
for i in "${array[@]}"
do
for j in "${array[@]}"
do
sum=$(($j+$i))
if [ $sum == $sanitised2ndParam ]
then
echo "$j + $i = $sum (TRUE)"
notFound=false
fi
done
done
if [ $notFound ]
then
echo "FALSE"
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment