Thread: store pi O.o;

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    26
    Umm, maybe this is a bit unconventional, but as this is just for this one function, you could go through a reasonable degree of pain and create your own set of functions to do it. Seeing your a newbie programmer (like myself), I think you'd like it better if you did it yourself. And I guess you basically want to do it (it doesn't have to be a rational thing to do, but you'll still learn a lot from it). This is what I'm thinking:
    Let the number be a linked list. That way, you can extend the number upto wherever you'd like it to go to. Then define addition. I guess by adding another property to your linked list (from here on ll) called length, and previous (instead of next, as your gonna go backwards) you could proceed. For addition, you get the last digit of the shorter ll, and add it to the position of the other ll. You can easily add a carry on function. You could do a similar process with multiplication. All of the numbers of the shorter ll multiply into each element of the longer ll. Carry ons of course apply. As you'll be dealing with decimals, you'll have to make a separation between the two also. I guess, could also separate the ll at creation, by making two sub lls, integral part and fractional part. You also have to make a good function for input and output(this is easy). I guess you could do all the other operations but that would require a bit more thought (especially for division)

    I know this seems like a lot of work, but I don't really see another way around it with the little I know.

  2. #17
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I know this seems like a lot of work
    It is. That's why some smart people have done it already. swox.com/gmp Mostly anything you come up with is a tincan compared to it.

    By the way, 15 digits of pi (what you can fit into a double) is enough to calculate the diameter of the Earth correct to the nanometer. What else would you want pi for...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    26
    As I said before, I don't think this is very rational, but I'm just suggesting that if you really want to do it, you could try this. It's just an idea. And I happen to be a newbie programmer with very little c++ experience, so if nobody could have figured a better more efficient way already, I'd be surprised.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Pi - Hm, somethign is not right here.
    By MadnessRed in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2008, 01:07 PM
  3. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 02:27 PM
  4. Pi Calculation
    By EvilGuru in forum C Programming
    Replies: 2
    Last Post: 05-02-2005, 04:25 AM
  5. C for PI
    By Lynux-Penguin in forum C Programming
    Replies: 13
    Last Post: 04-28-2002, 07:37 PM