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

Pages: 1-4041-

/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

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

It works on that link (Firefox and IE tested), put a number (and nothing else) in the input field. I don't exactly put error handling in brainfuck.

That implementation is very strict and if it works there, it should work everywhere. No moving to before memory cell 0, no overflowing or underflowing. EOF = 0. Moving past 30000 is allowed to be Turing complete, but this program doesn't go there by far.

Only issue with my code is that the highest number you can input is 254 before the counter overflows. I guess it gets weird input on your implementation.

And yes, it's supposed to output 3.142857 repeating. That's 22 / 7, it's pretty hard to really calculate pi in brainfuck.

Name: Anonymous 2007-09-14 11:03 ID:Heaven

>>41
It works on that link (Firefox and IE tested), put a number (and nothing else) in the input field.
Ah, now it works

Very nice work.

Name: Anonymous 2007-09-14 13:09 ID:p0bpMm5E

It's really too bad that in the real world, you never have to do stuff like calculate Pi or factorials, because that's pretty much the only thing useless toy languages really shine at.

Name: Anonymous 2007-09-14 15:37 ID:+p85jMAE

so far nothing has been successful... lol

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

>>27
>>44
This ``challenge'' is officially crap. Methods of pi digit extraction are no secret, and most are trivial to implement. This tests your ability to use Google and nothing else.

Name: Anonymous 2007-09-14 17:16 ID:Heaven

>>1
Read SICP (Section 3.5.3)

Name: Anonymous 2007-09-14 21:52 ID:+p85jMAE

I see this challenge has failed. I shall come up with another.

Name: Anonymous 2007-09-14 21:59 ID:xBurq3xB

>>32
pi in base pi would be 10.

Name: Anonymous 2007-09-14 22:00 ID:xBurq3xB

>>45
found it myself. Go fuck yourself faggots. 90% of you can't program but just talk about how satoori you are when you shove SICP up your asshole

Name: Anonymous 2007-09-14 22:01 ID:W3mYKou3

1 in base 1 would be 10

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

>>50
It would also be any one of these
1
10
100
10000
1000000000000000000000

Name: Anonymous 2007-09-14 22:13 ID:MPVsRCXO

<?php

get_pi();

?>

winrar

Name: Anonymous 2007-09-14 22:14 ID:pmk4hbO8

Protip: Use Manchin's formula:
pi = 4*(4*arctan(1/5) - arctan(1/239))

If you want it more precise:
pi = 4*(183*atan(1/239)+32*atan(1/1023)-68*atan(1/5382)+12*atan(1/113021)-100*atan(1/6826318)-12*atan(1/33366019650)+12*atan(1/43599522992503626068))

Use modulus division to get the digit you want. Trivial.

But, let's get serious... pi to 30 digits is enough to compute the visible universe with almost no error. For most cases, you don't need lots of digits. It's a parlor trick.

Next?

Name: Anonymous 2007-09-14 22:16 ID:pmk4hbO8

>>53
It'd be better if I didn't flip digits around, and I spelled Jon Machin's name right.

4*(183*atan(1/239)+32*atan(1/1023)-68*atan(1/5832)+12*atan(1/113021)-100*atan(1/6826318)-12*atan(1/33366019650)+12*atan(1/43599522992503626068))

Fix'd.

Name: Anonymous 2007-09-14 22:18 ID:ZdnvaXeQ

2 in base φ would be 10.01

Name: Anonymous 2007-09-14 22:20 ID:qEUxmkj+

A student was complaining about digital numbers. 'When I take the root of two and then square it again, the result is already inaccurate!'. Overhearing him, Fu-Tzu laughed. 'Here is a sheet of paper. Write down the precise value of the square root of two for me.'

Name: Anonymous 2007-09-14 22:23 ID:pmk4hbO8

>>56
e^(.5*ln(x)).

Works for me.

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

>>44
see
>>15

Name: Anonymous 2007-09-16 1:23 ID:VnCbxHj3

>>53
only person who know how to do it ITT
everyone is a butthurt faggot that can't admit there's some things they don't know.

Name: Anonymous 2007-09-16 1:32 ID:Heaven

>>59
trying too hard

Name: Anonymous 2007-09-16 4:44 ID:Heaven

>>60
faggot

Name: Anonymous 2007-09-16 5:16 ID:D97PAMV/

>>53
>>59

same person?

Name: Anonymous 2010-12-06 10:15

Are you GAY?
Are you a Haskell Programmer?
Are you a Raging Animu Fanboi?

If you answered "Yes" to all of the above questions, then /praque/ might be exactly what you've been looking for!

Name: Anonymous 2011-02-03 4:57

Name: Anonymous 2011-02-18 13:41

dubz

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