# the ramanujan number- john cook’s exercise

Disclaimer: OK, it’s midnight here and am too sleepy to actually write error-free code, but let me try the algorithm/logic of solving the problem john cook posed here.. It may be incomplete.

Ok. it’s clear that we need 4 distinct numbers that can be paired up to form the same sum.
It’s also clear that these summation pairs need to be relatively prime. (no that’s not right. it’s that all these 4 numbers need to relatively prime.) because of the condition the smallest number. if these 4 numbers have a common factor, you can take out the factor and ergo, you have a

— Aargh that’s some faulty reasoning. there.

Ok let me work at the other end. there’s a number ‘n’. that can be split into sum of two numbers. If we consider whole numbers, for any n, there can be n combinations of number pairs.

Our goal is to find two number pairs(tuple, if you will) (a,b) and (c,d) such that
1. a,b,c,d are all 4th powers of some number. i.e: 4th root of a,b,c,d are integers.
2. a+b = n = c +d.
3. n is the smallest such number.

Now the first two conditions are reasonably straightforward operations in computation.*
3. How do i codify that or translate into arithmetic operators, without having to iterate through all numbers 1 .. n?

ok, it does mean that a,b,c,d have to be relatively prime to each other**. (Oops wrong again the fourth roots of a,b,c,d, let’s call them a4,b4,c4,d4 they should be relatively prime)

*– I can’t recall the actual implementation of sqrt/pow(1/4) at the moment, but not really a problem.
** — allowing for 1 being treated very ambiguously and the multiplicative identity property of 1 ignored. (hmm.. i don’t like the sound/look/feel/smell:-P of that)

Anyway, let me try to write out a pseudo code sort of thing. with haskell type system.
``` prime_numbers = infinite list via one of the sieve implementation**```

``` relative_prime:: Int -> list(size n)* -> Bool -- A function that takes an integer and a list of integers with size of that integer and returns Boolean. -- it would be a function that takes a list of integers and returns a boolean. the size of list is extraneous, in python or rather imperative programming, it can be used as a error check/ sanity check on input values. but not necessary in haskell. integers = infinite list generated by adding 1 to the prev. result starting at 0 or 1?? recursive definition. is_fourth_power :: integer -> Bool is_sum :: [Integer] ->Integer -> Bool ```

* — however the hell that is represented in haskell.
**– which one, and what the hell to do with that annoying odd 1 ??

This site uses Akismet to reduce spam. Learn how your comment data is processed.