aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/rosetta/harmonic_series.bruijn
blob: 2395933b612653e5e4903e0db3e8b366d8c69270 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
:import std/List .
:import std/Combinator .
:import std/Math/Rational Q
:import std/Number N

harmonic [0 &[[(Q.add 1 op) : N.++0]] start [[1]]] ⧗ Unary → Rational
	op (+1) : N.--0
	start (+0.0f) : (+1)

custom-gt? &[[[N.gt? 2 (N.mul 0 N.++1)]]] ⧗ Rational → Νumber → Boolean

main [φ cons first-20 first-10-above (harmonic <$> (iterate [[[1 (2 1 0)]]] (+0u)))]
	first-20 take (+20)
	first-10-above [take (+10) first-above]
		first-above [find-index [custom-gt? 0 1] 1] <$> (iterate N.inc (+0))