Cool numeric example in python

2011-02-01 at 23:35:14 | categories: scripts

Magic of the math

Once I come across a PPS showing some magic in numbers, like adding this to that so many times looks so, etc. It looked really interesting, so to check this out this small script was created. Numbers are sometimes amazing :-)

Run it to see some beauty of math :)

You can fetch the script here.

#!/usr/bin/env python
# Some funny math facts...
# Author: mirek in domain opoki.com

def f1 ():
    s = ""

    for n in range (1, 10):
        s += str (n)
        res = int (s) * 8 + n
        print "%9s x 8 + %d = %d" % (s, n, res)

def f2 ():
    s = ""

    for n in range (1, 10):
        s += str (n)
        res = int (s) * 9 + n + 1
        print "%9s x 9 + %d = %d" % (s, n + 1, res)

def f3 ():
    s = ""
    tmp = 9
    for n in range (7, -1, -1):
        s += str (tmp)
        tmp -= 1
        res = int (s) * 9 + n
        print "%9s x 9 + %d = %d" % (s, n, res)


if __name__ == "__main__":
    f1 ()
    f2 ()
    f3 ()