Skip to content

Commit 7b3381a

Browse files
author
Dierk Koenig
committed
web: update examples page
1 parent 9ae7dce commit 7b3381a

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

docs/examples.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ <h2>Sequences</h2>
166166
<a href="./src/examples/sequence/BeautifulMath.html">Beautiful Math</a> when
167167
distributed over a circle?
168168
</dd>
169+
<dt><a href="./src/examples/sequence/Collatz.html">Collatz Number Exploration</a>
170+
</dt>
171+
<dd>Explore the
172+
<a href="./src/examples/sequence/Collatz.html">Collatz Numbers</a>. With the help
173+
of sequences and memoization you can browse through them in realtime.
174+
</dd>
175+
<dt><a href="./src/examples/sequence/Leibniz_Nilakantha.html">Approximating PI</a>
176+
</dt>
177+
<dd>Different sequences to approximate PI like
178+
<a href="./src/examples/sequence/Leibniz_Nilakantha.html">Gregory, Leibniz, and Nilakantha</a>
179+
have shown. We use the sequence API and the "limit" helper to celebrate their work
180+
in a functional approach.
181+
</dd>
169182
<dt><a href="./src/examples/sequence/fibonacci/Fibonacci.html">Fibonacci</a></dt>
170183
<dd>While the fibonacci sequence is of course everybody's favorite,
171184
it is also lends itself to a nice graphical <a href="./src/examples/sequence/fibonacci/Fibonacci.html">

docs/src/examples/sequence/Leibniz_Nilakantha.html

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,44 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Kolibri Tryout</title>
6+
<style>
7+
body {
8+
font-family: system-ui;
9+
font-variant-numeric: tabular-nums;
10+
padding: 2em;
11+
}
12+
</style>
613

714
</head>
815
<body>
16+
17+
<h1>The Heros approximating PI</h1>
18+
919
<pre>
1020
Gregory - Leibniz Series
1121

1222
4 4 4 4 4
1323
--- - --- + --- - --- + --- ...
1424
1 3 5 7 9
1525

16-
26+
<span id="leibnizOut"></span>
1727

1828
Nilakantha Series
1929

2030
4 4 4 4
2131
3 + --- - --- + --- - --- ...
2232
2*3*4 4*5*6 6*7*8 8*9*10
2333

34+
35+
<span id="nilaOut"></span>
36+
2437
</pre>
2538

2639

2740
<script type="module">
2841

29-
import {ALL, Walk, limit, plus, Seq} from "../../kolibri/sequence/sequence.js";
42+
import { ALL, Walk, limit, plus, Seq } from "../../kolibri/sequence/sequence.js";
43+
import { select } from "../../kolibri/util/dom.js";
3044

3145

3246
const partialSum = numSeq => n =>
@@ -50,12 +64,27 @@
5064
.map( n => 1 / (n * (n + 1) * (n + 2)))
5165
.zipWith((x, sign) => sign * x)(plusMinus);
5266

53-
const leibniz = 4 * limit(1e-3, partialSumSeq(leib_seq) );
54-
const nilakantha = 3 + 4 * limit(1e-8, partialSumSeq(nila_seq) );
55-
console.log( leibniz );
56-
console.log( nilakantha );
57-
console.log( Math.PI );
67+
const partialLeibnizSums = partialSumSeq(leib_seq);
68+
const leibniz = 4 * limit(1e-3, partialLeibnizSums );
69+
70+
const partialNilaSums = partialSumSeq(nila_seq);
71+
const nilakantha = 3 + 4 * limit(1e-8, partialNilaSums );
72+
73+
const [lout] = select(document.body, "#leibnizOut");
74+
lout.textContent = `
75+
Partial sum sequence
76+
${partialLeibnizSums.show()}
77+
78+
Limit * 4: ${leibniz}
79+
`;
80+
81+
const [nout] = select(document.body, "#nilaOut");
82+
nout.textContent = `
83+
Partial sum sequence
84+
${partialNilaSums.show()}
5885
86+
limit * 4 + 3: ${nilakantha}
87+
`;
5988
</script>
6089

6190

0 commit comments

Comments
 (0)