Programming challenge

How about a programming challenge?

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.

Edit: In the order that I received them
1 Pudge bash
2 @anon43355446 python C++
3 @anotherusername bash python perl
4 @Kresimir bash
5 @jonathon bash
6 @nate bash PHP JavaScript
7 @MrToddarama bash
8 @xircon bash

I hope I didn’t miss anybody, if so let me know.

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.

Still accepting scripts.

Pudge

10 Likes

LOL! How about python or C++??? :face_with_head_bandage:

3 Likes

What ever you prefer. I was saying bash script to be more inclusive. I think more people would know bash than Python or C++ ?

Pudge

1 Like

Hell knows. Bash has been always PITA to me. :slight_smile:

1 Like

How about an excel macro?

I’ll see myself out. Thanks.

:door:

5 Likes

Actually, I would like to see that.

Pudge

1 Like

Is this a class assignment ? :face_with_raised_eyebrow:

3 Likes

It’s extra credit.

Pudge

3 Likes

Is this going to be your new forum membership question (like when you register on the Arch forum).

:rofl:

10 Likes

Really like this one. And thanks :slight_smile:

1 Like

If you’re up for Perl I’ll take you on with Python :wink: (No C++ though. No experience with that one)

1 Like

In python it’s 5 minutes job. Unfortunately I know nothing on perl.

1 Like

I’d say not even 5 minutes :wink:

No matter, let’s see the Python one’s?

1 Like

It’s CIA internship program for finding outstanding mind for further corruption! :laughing:

2 Likes

Actually it took me more time: had to set up a python environment on Win10 at the office. :slight_smile:

2 Likes

You’re out of the competition :slight_smile: no hard feelings.

Jk. How about you also do your C++ and I’ll counter it with Perl.

2 Likes

Why not? But it must wait till I’m back home. 9:30 am here :confused:

2 Likes

Sure. No problem from this side.

1 Like

Yes, how did you guess?!? It will also be followed by a 15 min. psychological test… :crazy_face:

8 Likes
➜  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

Interesting.

3 Likes