Write a simple bash script that solves the following:
For all 4 digit integers, such as 1234, divide it in the middle to get two 2 digit numbers 12 & 34
Add the two 2 digit numbers
square the sum
the result is the original 4 digit number and the square of the sum are equal.
print out all of the four digit numbers for which this is true.
BTW 1234 is not one of these numbers, I just used it for an example
To make the syntax correct, the file must begin with
#!/bin/bash
and end with
exit
DO NOT print your resulting script here on the forum. Let’s give everyone who wishes to participate a chance.
Message me with your script listing, I will try it and if it passes the test I will add your name to the following list in this Original Post.
I tried them all. All produced the correct results except for one which had a syntax error in a language other than bash that I am not familiar with, and would not run.
This was really interesting on my end. I was surprised at the diversity of programming styles, and the difference in execution time between them.
➜ time python numbers.py
xxx
python numbers.py 0.07s user 0.01s system 98% cpu 0.082 total
➜ time sh ./numbers.sh
xxx
sh ./numbers.sh 33.80s user 21.93s system 731% cpu 7.623 total
➜ time perl numbers.pl
xxx
perl numbers.pl 0.01s user 0.01s system 96% cpu 0.019 total