Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/PROG/ Challenge Number 3 - Pi

Name: Anonymous 2007-09-13 22:45 ID:IZip/Yni

Make a program to calculate pi to the n'th decimal. Input the variable at runtime.  Program In the language of you choice. (and none of the print"3.1415" crap.)

Name: Anonymous 2007-09-13 22:48 ID:Heaven

print"PI!"
print"3.";
for i = 1 to 100
  print int(rnd(1)*9);
next

A 1 in a 327819053475987334554890734 chance of working!

Name: Anonymous 2007-09-13 22:49 ID:/BBjeZZn

JAVA LOL
FINDING PI METHOD #1

import java.util.Random;
public class PiFinder
{
    public double piSeries(int numberOfTerms)
    {
        boolean add = true;
        double answer = 0.0;
        double first = 1.0;
        while (numberOfTerms > 0) {
            if (add) {
                answer += (1 / first);
                first += 2;
                add = false;
                numberOfTerms--;
               }
            else {
                answer -= (1 / first);
                first += 2;
                add = true;
                numberOfTerms--;
               }
           }
            return (answer * 4);
    }
}



Name: Anonymous 2007-09-13 22:50 ID:mmgF6akB

char calculate_pi(int n)

sorry the rest is encapsulated for your protection.

Name: Anonymous 2007-09-13 22:53 ID:Heaven

>>3
[c]
java.lang.NoSuchMethodError: main
Exception in thread "main"
[/c]
...nice

Name: Anonymous 2007-09-13 22:54 ID:Heaven

[cc]
java.lang.NoSuchMethodError: main
Exception in thread "main"
[/cc]

test

Name: Anonymous 2007-09-13 22:54 ID:IZip/Yni


java.lang.NoSuchMethodError: main
Exception in thread "main"

Name: Anonymous 2007-09-13 22:55 ID:IZip/Yni

>>7
Neat! I AM IZip!

Name: Anonymous 2007-09-13 22:55 ID:Heaven


IM RETARDED LOL
/

Name: Anonymous 2007-09-13 22:57 ID:Heaven

LOL

Name: Anonymous 2007-09-13 23:05 ID:pPtzfgqm

series n = s / (2 * n + 1)
    where s | even n = 1
            | odd n = -1
pi-aproximations = map series [0.0..]
accurate nth (a,b) = abs (a - b) < 10 ^^ (-1 * nth)
pi nth = head (filter (accurate nth) (zip pi-aproximations (tail pi-aproximations)))

Name: Anonymous 2007-09-13 23:41 ID:mNLTXYkN


import gmpy
gmpy.pi(100000000)

Name: Anonymous 2007-09-13 23:45 ID:+/WmVVNp

lol noone is smart enough to do it. good challenge

Name: Anonymous 2007-09-14 1:37 ID:Ieoi1S0b

(defun pi () (/ 22 7))

Nice challenge, lol.

Name: Anonymous 2007-09-14 2:17 ID:L/6D3QNO

#include <stdlib.h>
#include <stdio.h>

void ComputePi(int numdigits, char* pi)
{
    int alength = 10 * numdigits / 3;
    int* a = (int*) malloc(alength * sizeof(int));
    int piLength = 0;
    int nines = 0;
    int predigit = 0;
    int i, j;
    for(i = 0; i < alength; ++i)
        a[i] = 2;

    for (j = 0; j < numdigits; ++j)
    {
        int q = 0;
        int p = 2 * alength - 1;
        for (i = alength; --i >= 0; )
        {
            int x = 10*a[i] + q*(i+1);
            a[i] = x % p;
            q = x / p;
            p -= 2;
        }

        a[0] = q % 10;
        q /= 10;
        if (q == 9)
            ++nines;
        else if (q == 10)
        {
            int k;
            pi[piLength] = (char) (predigit + 1 + '0');
            for (k = 1; k <= nines; ++k)
                pi[piLength+k] = '0';
            piLength += nines + 1;
            predigit = 0;
            nines = 0;
        }
        else
        {
            int k;
            pi[piLength] = (char)(predigit + '0');
            predigit = q;
            for (k = 1; k <= nines; ++k)
                pi[piLength + k] = '9';
            piLength += nines + 1;
            nines = 0;
        }
    }
    pi[piLength] = (char)(predigit + '0');
    pi[piLength+1] = '\0';

    free(a);
}

int main(int argc, char** argv)
{
    int numdigits;
    char* pi;

    if (argc <= 1)
    {
        fprintf(stderr, "usage: pi #DIGITS [FILE]");
        return 1;
    }

    numdigits = atoi(argv[1]);
    pi = (char*) malloc(numdigits+1);
    ComputePi(numdigits, pi);

    if (argc > 2)
    {
        FILE* fp = fopen(argv[2], "w");
        if (fp == NULL)
        {
           fprintf(stderr, "Cannot open %s\n", argv[2]);
           return 2;
        }
        fputs(pi, fp);
        fputc('\n', fp);
        fclose(fp);
    }
    else
        puts(pi);

    free(pi);

    return 0;
}

Name: Anonymous 2007-09-14 4:11 ID:cVEL7WgC

>>13
its easy + boring

Name: Anonymous 2007-09-14 4:36 ID:1PEoexAv

I don't like these ``party trick'' challenges. The ``practical'' one was much nicer.

Name: Anonymous 2007-09-14 4:39 ID:Heaven

>>14
hahaha, oh wow

Name: Anonymous 2007-09-14 4:47 ID:wdLYeR/7

>>14
I remember an episode of "Jim'll Fix It" in the late 80s where a nerdy young girl wrote in asking him if he could fix it for her to calculate the value of Pi. So they brought her in the studio and had her calcuate 22/7 to about 50 decimal places. I lol'd.

Name: Anonymous 2007-09-14 4:57 ID:Ieoi1S0b

>>19 I lol'd.
I don't get the joke. #_#

Name: Anonymous 2007-09-14 5:12 ID:KbXYyqA9

>>20
Any integer divided by 7 is a repeated decimal, in this case 3.142857

Name: Anonymous 2007-09-14 5:22 ID:WWWs1FtP

>>21
EXPERT BBCODE PROGRAMMER

Name: Anonymous 2007-09-14 6:15 ID:UJWp9g5V

>>22
ID:WWWs1FtP

WHAT THE FUCK

Name: Anonymous 2007-09-14 6:21 ID:QO2KWuvl

pi = '3.1415.....................'
def PiDigits(digits):
    if digits <= 0:   return 0
    elif digits == 1: return 3
    else:             return pi[:digits + 1]


>>22
EXPERT WEB DEVELOPER ID

Name: Anonymous 2007-09-14 6:25 ID:Heaven

>>24
that .......... really works? wtf

Name: Anonymous 2007-09-14 6:35 ID:Heaven

>>25
It doesn't.

Name: Anonymous 2007-09-14 7:20 ID:+p85jMAE

lol can no one do this CHALLENGE?!?!??!

Name: Anonymous 2007-09-14 7:23 ID:Heaven

>>27
Find me a simple algorithm that doesn't use floating point numbers and I'll implement it.

Name: Anonymous 2007-09-14 7:30 ID:Heaven

>>28
How about you program your own code.

Name: Anonymous 2007-09-14 7:33 ID:YNIbXAoJ

#define LOCALE "Alabama"

printf("3.");
for (int i = 0; i < precision; i++)
        printf("0");
printf("\n");

Name: Anonymous 2007-09-14 7:33 ID:Heaven

>>29
HOW DO I SHOT PI WITHOUT FLOATING POITNS!?!!?

Name: Anonymous 2007-09-14 7:43 ID:xohWmWF5

i have written my program in base pi.

System.out.println("1");

Name: Anonymous 2007-09-14 8:17 ID:yeLJ08KY


wget --quiet -O - http://tinyurl.com/35ebo5

This sh program uses a client/server architecture.

Name: Anonymous 2007-09-14 8:33 ID:QO2KWuvl

>>26
It DOES work >:o

Name: Anonymous 2007-09-14 9:46 ID:WWWs1FtP

>>++++++[->++++++++<]<+++>>[-<+<+>>]<<.-----.[-]>[->+<]>>,[+[<]>[<+[>]<-[<]>>-]<[->+<]>[>],]<[<]>>>[<-[->++++++++++<]<[->+<]>>>]<-[-<+.>[-<+++.    >[-<--.>[-<++++++.>[-<---.>[-<++.-------<]]]]]>>]

Name: Anonymous 2007-09-14 9:48 ID:Heaven

>>35
stops at 3. .. am i doin something wrong? i guess endless loop?

Name: Anonymous 2007-09-14 10:05 ID:WWWs1FtP

>>36
"calculate pi to the n'th decimal. Input the variable at runtime"

Name: Anonymous 2007-09-14 10:09 ID:Heaven

>>37


./parse BFfile
3.3<enter>

stays there?

Name: Anonymous 2007-09-14 10:24 ID:WWWs1FtP

You need to end your input with an EOF (usually ^D or ^Z, depends on your implementation and OS). Also, if your implementation is slow it can take a while.

Use http://fr33ke.googlepages.com/jsbrainfuck.html (very strict and fast interpreter) if you still have problems.

Name: Anonymous 2007-09-14 10:35 ID:XB8sWze4

>>39
your code in that link does not work

Error: value at [4] smaller than 0


I'm using my own implementation, i typed 3^D and i got
85714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714

etc etc, is that supposed to be the output of `3'?
Please mention if the memory can be looped (eg < is the last cell) and what value the cell has if EOF is read

My implementation allows < (or > in the end) and EOF = 0

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List