Friday, September 14, 2007

Beauty of Math using Linux

This evening, I received an email showing me several beauty of math numbers, that fascinated me.

This email of Beauty of Math Numbers is not really related to my linux blog. However, my attempt for tracing the DNA relation of this beauty of math numbers to linux family genes has been successful for the past few minutes and I would like to share it here.

A set of number patterns will be shown one at a time and I would try to achieve the same effect using simple bash scripting as we move along live.

I have to copy and paste from the email that I received.

Here goes the first contestant of the Beauty of Math in Linux.

1 x 8 + 1 = 9
12 x 8 + 2 = 98
123 x 8 + 3 = 987
1234 x 8 + 4 = 9876
12345 x 8 + 5 = 98765
123456 x 8 + 6 = 987654
1234567 x 8 + 7 = 9876543
12345678 x 8 + 8 = 98765432
123456789 x 8 + 9 = 987654321

See the pretty number patterns above?

Now here's goes my freshly made linux bash script to achieve the same mathematical computation and match display shown above:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#/bin/bash
x=1
constant=8
array=(1 12 123 1234 12345 123456 1234567 12345678 123456789)
while [ $x -lt 10 ] ;
do
let product=${array[$x-1]}*$constant+$x
echo ${array[$x-1]} x $constant + $x = $product
let x=$x+1;
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Screen Output:
1 x 8 + 1 = 9
12 x 8 + 2 = 98
123 x 8 + 3 = 987
1234 x 8 + 4 = 9876
12345 x 8 + 5 = 98765
123456 x 8 + 6 = 987654
1234567 x 8 + 7 = 9876543
12345678 x 8 + 8 = 98765432
123456789 x 8 + 9 = 987654321
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Now, the second contestant for the Beauty of Math using Linux bash scripting.

1 x 9 + 2 = 11
12 x 9 + 3 = 111
123 x 9 + 4 = 1111
1234 x 9 + 5 = 11111
12345 x 9 + 6 = 111111
123456 x 9 + 7 = 1111111
1234567 x 9 + 8 = 11111111
12345678 x 9 + 9 = 111111111
123456789 x 9 +10= 1111111111

And here's my equivalent bash script for that

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#/bin/bash
x=2
constant=9
array=(1 12 123 1234 12345 123456 1234567 12345678 123456789)
while [ $x -lt 11 ] ;
do
let product=${array[$x-2]}*$constant+$x
echo ${array[$x-2]} x $constant + $x = $product
let x=$x+1;
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Output:
1 x 9 + 2 = 11
12 x 9 + 3 = 111
123 x 9 + 4 = 1111
1234 x 9 + 5 = 11111
12345 x 9 + 6 = 111111
123456 x 9 + 7 = 1111111
1234567 x 9 + 8 = 11111111
12345678 x 9 + 9 = 111111111
123456789 x 9 + 10 = 1111111111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, the third contestant from the Beauty of Math in Linux:

9 x 9 + 7 = 88
98 x 9 + 6 = 888
987 x 9 + 5 = 8888
9876 x 9 + 4 = 88888
98765 x 9 + 3 = 888888
987654 x 9 + 2 = 8888888
9876543 x 9 + 1 = 88888888
98765432 x 9 + 0 = 888888888

which has an equivalent bash script code shown below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#/bin/bash
x=7
y=0
constant=9
array=(9 98 987 9876 98765 987654 9876543 98765432)
while [ $y -lt 8 ] ;
do
let product=${array[$y]}*$constant+$x
echo ${array[$y]} x $constant + $x = $product
let x=$x-1;
let y=$y+1;
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Equivalent screen output:
9 x 9 + 7 = 88
98 x 9 + 6 = 888
987 x 9 + 5 = 8888
9876 x 9 + 4 = 88888
98765 x 9 + 3 = 888888
987654 x 9 + 2 = 8888888
9876543 x 9 + 1 = 88888888
98765432 x 9 + 0 = 888888888
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Brilliant isn't it?

Now, take a look at this next math symmetry.

1 x 1 = 1
11 x 11 = 121
111 x 111 = 12321
1111 x 1111 = 1234321
11111 x 11111 = 123454321
111111 x 111111 = 12345654321
1111111 x 1111111 = 1234567654321
11111111 x 11111111 = 123456787654321
111111111 x 111111111= 12345678987654321

Here goes its equivalent bash script for the above patterns:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#/bin/bash
x=0
array=(1 11 111 1111 11111 111111 1111111 11111111 111111111)
while [ $x -lt 9 ] ;
do
let product=${array[$x]}*${array[$x]}
echo ${array[$x]} x ${array[$x]} = $product
let x=$x+1;
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which has an equivalent terminal output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 x 1 = 1
11 x 11 = 121
111 x 111 = 12321
1111 x 1111 = 1234321
11111 x 11111 = 123454321
111111 x 111111 = 12345654321
1111111 x 1111111 = 1234567654321
11111111 x 11111111 = 123456787654321
111111111 x 111111111 = 12345678987654321
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Numerical Final Note:
~~~~~~~~~~~~~~~~~~~~

Numbers are interesting human-made and human-readable values that makes us real busy these computing days.

Any ideas who won this Beauty of Match Linux contest?

PS
Oh, I wonder how my black coffee with brandy (scotch coffee) helps me interpret these numbers into its equivalent bash script somehow.

Hope you enjoy reading them, cheers!

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy