Bernoulli numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: oops) |
||
Line 3,654: | Line 3,654: | ||
First, a straighforward implementation of the naïve algorithm in the task description. |
First, a straighforward implementation of the naïve algorithm in the task description. |
||
{{works with|Rakudo|2015.12}} |
{{works with|Rakudo|2015.12}} |
||
<syntaxhighlight lang="raku line |
<syntaxhighlight lang="raku" line>sub bernoulli($n) { |
||
my @a; |
my @a; |
||
for 0..$n -> $m { |
for 0..$n -> $m { |
||
Line 3,710: | Line 3,710: | ||
{{works with|Rakudo|2015.12}} |
{{works with|Rakudo|2015.12}} |
||
<syntaxhighlight lang="raku line |
<syntaxhighlight lang="raku" line>constant bernoulli = gather { |
||
my @a; |
my @a; |
||
for 0..* -> $m { |
for 0..* -> $m { |
||
Line 3,787: | Line 3,787: | ||
{{works with|Rakudo|2016.12}} |
{{works with|Rakudo|2016.12}} |
||
<syntaxhighlight lang="raku line |
<syntaxhighlight lang="raku" line>sub infix:<bop>(\prev, \this) { |
||
this.key => this.key * (this.value - prev.value) |
this.key => this.key * (this.value - prev.value) |
||
} |
} |
||
Line 3,812: | Line 3,812: | ||
Same output as memoization example |
Same output as memoization example |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
The double sum formula used is number '''(33)''' from the entry [http://mathworld.wolfram.com/BernoulliNumber.html Bernoulli number] on Wolfram MathWorld<sup>TM</sup>. |
The double sum formula used is number '''(33)''' from the entry [http://mathworld.wolfram.com/BernoulliNumber.html Bernoulli number] on Wolfram MathWorld<sup>TM</sup>. |