This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Recursive implementation | |
func LeibnizPiApproximationFunc(#afterIterations: Int) -> Double | |
{ | |
// See http://stackoverflow.com/questions/24270693/nested-recursive-function-in-swift | |
var ApproxPi: (Double, Double, Double, Int) -> Double = { _ in return 0.0 } | |
ApproxPi = | |
{ | |
(denom : Double, factor : Double, piAccum: Double, iteration: Int) -> Double in | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gregory-Leibniz approximation of π | |
// See https://gist.github.com/jbagley/9558879 for C implementation | |
var factor = -1.0 | |
var piAccumulation = 4.0 | |
var denom = 3.0 | |
// If using in a playground beware this many iterations, try 2500 instead. | |
for i in 1…500000 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
// So I can change the type more easily. | |
typedef long double Float; | |
#define FloatFormat "%.30Lf" | |
#define SqRoot sqrtl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start the HTML and Javascript code | |
print ''' | |
<html> | |
<head> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("visualization", "1", {packages:["treemap"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
''' |