The Julia Programming Language

Calculating Pi

Objective

Improve Julia coding skills.

Introduction

This is an interesting one because the infinite sequence below converges to a number that relates to π. There are several ways to prove that although I like this one the most https://www.youtube.com/watch?v=d-o3eB9sfls.

1/1 + 1/4 + 1/9 + 1/16 + … = π^2 / 6

What to do?

Write a function mypi that takes a single argument n and returns the value of π.

There are a couple of ways to implement this function - most conventionally a for-loop if you are used to iterative programming style. Once you have the correct solution, try to implement it with functional programming techniques… perhaps you can do it with a single line of code!

How to submit your solution?

You can publish your code on GitHub in a repository or as a public gist. Include the link in the comments.

Task tags

  • pi
  • julia
  • math

Students who completed this task

Lauraf50, jseal, POPLOPUK, weCryOpen, Shehan Wijethunga, QualityTrash, thepoppycat, seanrk, QQCute, Daniel Z., A. A., Parth Thakur, nika02, aryan_02, Adstech

Task type

  • code Code

Level

Beginner
close

2019