Results 1 to 16 of 16

Thread: Ramanujan Cubes

  1. #1
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Ramanujan Cubes

    Hi,

    I made a simple Ramanujan cube solver (my teacher asked me to make a quick one to demonstrate to his grade 12 class on the first day of school). I made the original one in Java, but made a scar version aswell for fun Has the ability to do about 19.6 million numbers per second and Taxicab(3) within 7.5 seconds using JAVA, but SCAR can only do roughly 50,000 numbers per second, might take a few minutes when trying Taxicab(3) on SCAR. (these result are for me, on 2x1.83ghz processor)

    SCAR Code:
    procedure Ramanujan(rnum: Integer);
    var i, j, k, n: Integer;
        i3, j3, k3, n3: Integer;
        matches, started: Integer;
    begin
      started := GetSystemTime;
     
      repeat
        i := i + 1;
        i3 := i * i * i;
        j := i;
        if (i3 > rnum) then break;
        repeat
          j := j + 1;
          j3 := j * j * j;
          k := i + 1;
          if (i3 + j3 > rnum) then break;
          repeat
            k := k + 1;
            k3 := k * k * k;
            n := k;
            if (k3 > i3 + j3) then break;
            repeat
              n := n + 1;
              n3 := n * n * n;
              if (n3 + k3 > i3 + j3) then break;
              if (n3 + k3 = i3 + j3) then
              begin
                //Writeln(Format('%d = %d^3 + %d^3 = %d^3 + %d^3', [i3 + j3, i, j, k, n]));
                matches := matches + 1;
              end;
            until(n >= rnum);
          until(k >= rnum);
        until(j >= rnum);
      until (i >= rnum);

      Writeln(Format('Found %d Matches | Time Took: %dms', [matches, GetSystemTime - started]));
    end;

    begin
      Ramanujan(StrToInt(Readln('Number')));
    end.

    ---

    Java Version:
    Code:
    class Ramanujan
    {
      Ramanujan(int rnum)
      {
        long time = System.currentTimeMillis();
        
        int matches = 0;
        int i = 0, j = 0, k = 0, n = 0;
        int i3, j3, k3, n3;
        
        do
        {
          i++;
          i3 = i * i * i;
          j = i;
          do
          {
            j++;
            j3 = j * j * j;
            k = i + 1;
            do 
            {
              k++;
              k3 = k * k * k;
              n = k;
              do 
              {
                n++;
                n3 = n * n * n;
                if (n3 + k3 == i3 + j3)
                {
                  //System.out.println((i3 + j3) + " = " + i + "^3 + " + j + "^3 = " + k + "^3 + " + n + "^3");
                  matches++;
                }
              } while (n <= rnum && n3 + k3 < i3 + j3);
            } while (k <= rnum && k3 < i3 + j3);
          } while (j <= rnum && i3 + j3 < rnum);
        } while (i <= rnum && i3 < rnum);
        
        System.out.println("Found " + matches + " Matches | Time Took: " + (double)(System.currentTimeMillis() - time) / 1000);
      }
      
      static void main(String[] args)
      {
        try
        {
          int num = Integer.parseInt(new java.util.Scanner(System.in).next());
          new Ramanujan(num);
        } 
        catch(NumberFormatException nfe)
        {
          System.out.println("Please enter a numerical digit");
        }
      }
    }
    And a C# Version
    Code:
    using System;
    using System.Collections.Generic;
    
    namespace Ramanujan
    {
        class Ramanujan
        {
            Ramanujan(int rnum)
            {
                List<string> list = new List<string>();
                int matches = 0;
                int i = 0, j = 0, k = 0, n = 0;
                int i3, j3, k3, n3;
                int timestart = Environment.TickCount;
    
                do
                {
                    i++;
                    i3 = i * i * i;
                    j = i;
                    do
                    {
                        j++;
                        j3 = j * j * j;
                        k = i + 1;
                        do
                        {
                            k++;
                            k3 = k * k * k;
                            n = k;
                            do
                            {
                                n++;
                                n3 = n * n * n;
                                if (n3 + k3 == i3 + j3)
                                {
                                    list.Add((i3 + j3) + " = " + i + "^3 + " + j + "^3 = " + k + "^3 + " + n + "^3");
                                    matches++;
                                }
                            } while (n <= rnum && n3 + k3 < i3 + j3);
                        } while (k <= rnum && k3 < i3 + j3);
                    } while (j <= rnum && i3 + j3 < rnum);
                } while (i <= rnum && i3 < rnum);
    
                double timetook = (Environment.TickCount - timestart) / 1000;
                list.ForEach(new Action<string>(Console.WriteLine));
                Console.WriteLine("Found {0} Matches | Time Took: {1}s", matches, timetook);
            }
    
            static void Main(string[] args)
            {
                Console.Write("Enter Search Limit: ");
                try
                {
                    int limit = Int32.Parse(Console.ReadLine().Trim());
                    new Ramanujan(limit);
                }
                catch (FormatException fe) { throw new FormatException(fe.Message); }
                Console.Read();
            }
        }
    }

    LOLCODE version (as suggested by Freddy):
    Code:
    HAI
    CAN HAS STDIO?
    I HAS A rnum
    I HAS A matches
    
    BTW fill in the number limit on next line
    rnum IZ 100000
    
    VISIBLE "Starting Ramanujan, Limit: " rnum
    IM IN YR LOOP, UPPIN YR i!!1 TILL rnum
    	I HAS A i3 ITZ i BOOM 3
    	IS i3 BIGGER THAN rnum?
    		YA RLY 
    			THATS ALL
    	OKTHX
    	
    	I HAS A j ITZ i TIEMZ 1
    	IM IN YR INNER_LOOP, UPPIN YR j!!1 TILL rnum
    		I HAS A j3 ITZ j BOOM 3
    		IS i3 UP j3 BIGGER THAN rnum?
    			YA RLY 
    				THATS ALL
    		OKTHX
    		
    		I HAS A k ITZ i UP 1
    		IM IN YR LOOP, UPPIN YR k!!1 TILL rnum
    			I HAS A k3 ITZ k BOOM 3
    			IS k3 BIGGER THAN i3 UP j3?
    				YA RLY 
    					THATS ALL
    			OKTHX
    			
    			I HAS A n ITZ k
    			IM IN YR INNER_LOOP, UPPIN YR n!!1 TILL rnum
    				I HAS A n3 ITZ n BOOM 3
    				
    				IS n3 UP k3 BIGGER THAN i3 UP j3?
    					YA RLY 
    						THATS ALL
    				OKTHX
    				
    				IS n3 UP k3 LIEK i3 UP j3?
    					YA RLY 
    						VISIBLE i3 UP j3 " = " i "^3 + " j "^3 = " k "^3 + " n "^3"
    						UP matches!!1
    				OKTHX
    			IM OUTTA YR INNER_LOOP
    		IM OUTTA YR LOOP
    	IM OUTTA YR INNER_LOOP
    IM OUTTA YR LOOP
    VISIBLE "Found a total of: " matches " matches!"
    KTHXBAI


    ~NS
    Last edited by Nadeem; 09-14-2009 at 01:06 AM.

  2. #2
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Whats a Ramanujan cube ?

  3. #3
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by caused View Post
    Whats a Ramanujan cube ?
    They are numbers cubed which happen to have summed matches, well kinda hard for my to explain without showing you anything so: http://www.durangobill.com/Ramanujan.html



    ~NS

  4. #4
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    That Ramanujan was insane... He has invented insane Pi approximations without any calculators :S For example


    I like solving maths problems with computer

  5. #5
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    That Ramanujan was insane... He has invented insane Pi approximations without any calculators :S For example


    I like solving maths problems with computer
    lol yea he was a mathematical genius friggin mastered trig by age 13 and lead a whole damn research by age 17...crazy.



    ~NS

  6. #6
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    http://www.wolframalpha.com/input/?i...16887242097%29


    Dayum. I had to use a computer to do it, and he did it on his own?

    ~Sandstorm
    Last edited by Sandstorm; 09-08-2009 at 01:40 AM.

  7. #7
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Sandstorm View Post
    http://www.wolframalpha.com/input/?i=%2899^2%29+%2F+%282206+*+1.41421356237309504880 16887242097%29


    Dayum. I had to use a computer to do it, and he did it on his own?

    ~Sandstorm
    you mean
    http://www.wolframalpha.com/input/?i...8016887242097)
    ^^

    Here's even more accurate
    http://www.wolframalpha.com/input/?i...206+*+sqrt(2))
    7 decimals correct!

  8. #8
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Pff, no lolcode version...

  9. #9
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Freddy1990 View Post
    Pff, no lolcode version...
    Do want!


  10. #10
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol, Fine made a lolcode version Check first post!



    ~NS

  11. #11
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Nadeem View Post
    lol, Fine made a lolcode version Check first post!



    ~NS
    *hug*

  12. #12
    Join Date
    Sep 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So.. Much.. Win.. Haha ^^ Pretty cool stuff.. I guess we were doing these in my math class a few days ago, but they didn't say what the numbers were called..

  13. #13
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Freddy1990 View Post
    *hug*
    tehe
    Quote Originally Posted by ABC.def.GHI View Post
    So.. Much.. Win.. Haha ^^ Pretty cool stuff.. I guess we were doing these in my math class a few days ago, but they didn't say what the numbers were called..
    probably something similar, but a bit different all my math teachers know what's Ramanujan (done it in uni) so assuming most math teachers would know it when they are doing it



    ~NS

  14. #14
    Join Date
    Sep 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Nadeem View Post
    tehe

    probably something similar, but a bit different all my math teachers know what's Ramanujan (done it in uni) so assuming most math teachers would know it when they are doing it



    ~NS
    It was actually a lower math class (my math somehow didn't get on my transcript.. I got changed to a different math class now ) and I didn't go to class the day after we did those numbers.. Oh wait I just looked at the formula again and we were doing something else.. >_> Haha STILL! It's interesting.

  15. #15
    Join Date
    Mar 2010
    Location
    New Hampshire, U.S.A
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    That Ramanujan was insane... He has invented insane Pi approximations without any calculators :S For example


    I like solving maths problems with computer
    wrong

    i had scar calculate that, so whats the real calculation of pi

    i have always wondered how that is known

    PHP Code:
    program New;
    var 
    pi:double;
    begin
    pi 
    := (66*sqrt(2))/((33*sqrt(29))-148)
    writeln(pi);
    end

    \/supposed to be 2654 but otherwise pretty d4mn accurate
    3.14159263220337 is the result
    Sell botted goods at mid to high prices!!! Else we lose our profit AND ruin the game!!!!

  16. #16
    Join Date
    Dec 2007
    Location
    Williston, ND
    Posts
    3,106
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by g0tp0t View Post
    wrong

    i had scar calculate that, so whats the real calculation of pi
    That's why he said it was an approximation...

    also, please check post dates before you post, unless of course it is something so related to the thread that you don't want to justify creating a new one.
    Proud owner of "Efferator" my totally boted main account!
    "You see, sometimes, science is not a guess" -Xiaobing Zhou (my past physics professor, with heavy Chinese accent)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •