Questions tagged [pi]

This tag is for challenges involving the mathematical constant pi, the ratio of a circle's circumference to its diameter.

Filter by
Sorted by
Tagged with
88 votes
28 answers
8k views

Bake a slice of Pi

Write a program or function that prints or outputs this exact text (consisting of 142 characters): ...
Copper's user avatar
  • 3,910
37 votes
18 answers
12k views

Find the nth decimal of pi

There are already 30 challenges dedicated to pi but not a single one asks you to find the nth decimal, so... Challenge For any integer in the range of ...
Bassdrop Cumberwubwubwub's user avatar
36 votes
18 answers
6k views

Calculate 500 digits of pi

Write a program to calculate the first 500 digits of pi, meeting the rules below: It must be less than 500 characters in length. It cannot include "pi", "math.pi" or similar pi constants, nor may it ...
Thomas O's user avatar
  • 3,348
20 votes
5 answers
3k views

Calculate π with quadratic convergence

Write a function or complete program that takes a positive number n and performs n steps of an iterative algorithm for ...
aditsu quit because SE is EVIL's user avatar
18 votes
10 answers
2k views

stupid restrictions and desert

So, you were sitting at your desk, golfing a program to calculate the first 20 digits of pi, and along comes your boss and throws your apple IIe out the window. You are now working on a new project ...
hildred's user avatar
  • 1,427
17 votes
67 answers
10k views

Pi Calculation Code Golf [closed]

The Challenge You must calculate pi in the shortest length you can. Any language is welcome to join and you can use any formula to calculate pi. It must be able to calculate pi to at least 5 decimal ...
poseidon's user avatar
  • 367
38 votes
23 answers
4k views

Natural Pi #0 - Rock

Goal Create a program/function that takes an input N, check if N random pairs of integers are relatively prime, and returns <...
NonlinearFruit's user avatar
26 votes
20 answers
2k views

Co-primality and the number pi

Introduction Number theory is full of wonders, in the form of unexpected connections. Here's one of them. Two integers are co-prime if they have no factors in common other than 1. Given a number \$N\$,...
Luis Mendo's user avatar
  • 104k
19 votes
31 answers
8k views

Calculate pi to 5 decimals [closed]

This comes from http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/ "Given that Pi can be estimated using the function \$4 \times (1 - 1/3 + 1/5 - 1/7 + \cdots)\$ ...
nos's user avatar
  • 199
11 votes
6 answers
1k views

Transmit Pi... precisely

Following on from Monte Carlo estimator of Pi this challenge is to produce the shortest code for the constant Pi. Except here your code must output consecutive digits of pi forever. This is code ...
user avatar
56 votes
63 answers
17k views

Output Pi without math [closed]

In as few bytes as possible, your job is to write a program that outputs: 3.14 In celebration of a late Pi day of course! :) Rules You can do it anyway you ...
kukac67's user avatar
  • 2,189
27 votes
35 answers
4k views

Monte Carlo estimator of Pi

Happy Pi Day everyone! For no reason at all, I'm trying to construct a Monte Carlo estimator of Pi that is as short as possible. Can we construct one that can fit in a tweet? To clarify, what I have ...
keegan's user avatar
  • 397
7 votes
2 answers
7k views

Print the n-th digit of pi [duplicate]

Task Given an input n, calculate the n-th decimal digit of pi Rules Answer can be a full program or a function. Input must be taken from stdin or from function ...
penalosa's user avatar
  • 553
4 votes
3 answers
2k views

Solve the CodeSprint4 Leibniz code golf challenge in Python in 66 characters

Check out this challenge: https://www.hackerrank.com/codesprint4/challenges/leibniz (The competition has already ended, so I'm just curious about the Python solution, which the organizers refused to ...
Ram Rachum's user avatar
64 votes
43 answers
9k views

π Day puzzle for 3/14

Happy π Day. The goal of this question is to calculate the area for a circle of radius 3, where A = πr². The catch is that you have to use the constant π that is defined in a different language than ...
Kevin's user avatar
  • 3,131
27 votes
9 answers
4k views

Map a random number to pi

A double precision representation of a decimal can only guarantee an accuracy of 15 decimal places, thus pi is approximated as: 3.141592653589793 You can see ...
Stewie Griffin's user avatar
27 votes
8 answers
9k views

Pi is still wrong [closed]

Pi is Wrong A common method of computing pi is by throwing "darts" into a 1x1 box and seeing which land in the unit circle compared to the total thrown: ...
Kyle Kanos's user avatar
  • 4,362
26 votes
37 answers
8k views

Happy Rounded Pi Day

To celebrate Rounded Pi Day, you must take advantage of today's date to make a program that takes in a circle's diameter and outputs its circumference by multiplying the diameter by 3.1416, where 3....
jmasterx's user avatar
  • 519
24 votes
11 answers
2k views

Good rational approximations of pi

Write a program that prints out all the good rational approximations of pi with denominator < 1000000, in increasing denominator order. a/b is a "good rational ...
Keith Randall's user avatar
21 votes
17 answers
2k views

Calculate Pi unto a point using the Nilakantha series

Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms. The Nilakantha series is as ...
SectorCorruptor's user avatar
17 votes
38 answers
3k views

Calculating π using the Gregory Leibniz series until n terms

based off my previous challenge, this wikipedia article, and a Scratch project Your task: given i, calculate \$\pi\$ till i ...
SectorCorruptor's user avatar
13 votes
6 answers
1k views

PI window encryption

This is a simple encryption method that uses PI digits to encode a message, the method is simple: The key is just a positive integer that indicates where the window starts then: Given a string to ...
BrunoJ's user avatar
  • 659
13 votes
35 answers
2k views

Output with the same number of digits of pi as the length of the code

Your challenge is to print x digits of pi where x is your code length. Examples: ...
MD XF's user avatar
  • 13.9k
12 votes
5 answers
1k views

Runs of Digits in Pi

Your goal is to output the strictly increasing sequence of consecutive, identical digits of pi (π). Each term in the sequence must be one digit longer than the previous. So ...
mbomb007's user avatar
  • 23.4k
12 votes
3 answers
442 views

Natural Pi #2 - River

Goal Given an string with a train of hashes, calculate its total length and divide by the distance from start to finish. Simulation What are we simulating? According to this paper, the ratio of the ...
NonlinearFruit's user avatar
12 votes
3 answers
655 views

Computing truncated digits sums of powers of pi

Given a positive integer n output the sum of the first n decimal digits of the fractional part of πn. Example input and outputs: 1 → 1 2 → 14 3 → ...
orlp's user avatar
  • 39.1k
9 votes
8 answers
2k views

Music with pi and e

Because I forgot to celebrate Pi Day (14.3), let's celebrate with \$\pi\$, \$e\$ (Euler's number) and music! Challenge No, we don't have time to eat a pi-pizza, let's make a program. What you need is ...
math scat's user avatar
  • 9,248