Thursday, July 17, 2014

Lesson 9 : Some fun

1729 is known as Hardy Ramanujam Number.  (There is a wiki article here). Reading the article all the way down, I read an interesting part that the Japanese Scientist Masahiki Fujiwara found out.

1729 –> add the numbers and you get 1+7+2+9=19

Reverse 19 and you get 91. 19x91=1729. According to him only 2 more numbers other than 1729 show this property. One is 81 and other is 1458. I decided to write a small piece of code to verify this.

for x=10 to 9999
' find the sum of numbers first
' reverse this number
' multiply it and you should get the original number
    n=x
    s=0
    while (n>0)
        s=s+(n mod 10)
        n=int(n/10)
    wend
'reverse s, call it rs
    if s<10 then
        rs=s
    else
        rs=(s mod 10) * 10 + int(s/10)
    end if
    if (s*rs = x) then
        wscript.echo x
    end if   
next

 

C:\scripts>nos.vbs //nologo
81
1458
1729

C:\scripts>

And yes there are only 3 numbers.

No comments: