Harmonic series: Difference between revisions
Content added Content deleted
(Added Tcl version) |
imported>Maxima enthusiast No edit summary |
||
Line 1,528: | Line 1,528: | ||
<pre>{1, 3/2, 11/6, 25/12, 137/60, 49/20, 363/140, 761/280, 7129/2520, 7381/2520, 83711/27720, 86021/27720, 1145993/360360, 1171733/360360, 1195757/360360, 2436559/720720, 42142223/12252240, 14274301/4084080, 275295799/77597520, 55835135/15519504} |
<pre>{1, 3/2, 11/6, 25/12, 137/60, 49/20, 363/140, 761/280, 7129/2520, 7381/2520, 83711/27720, 86021/27720, 1145993/360360, 1171733/360360, 1195757/360360, 2436559/720720, 42142223/12252240, 14274301/4084080, 275295799/77597520, 55835135/15519504} |
||
{2, 4, 11, 31, 83, 227, 616, 1674, 4550, 12367}</pre> |
{2, 4, 11, 31, 83, 227, 616, 1674, 4550, 12367}</pre> |
||
=={{header|Maxima}}== |
|||
<syntaxhighlight lang="maxima"> |
|||
harmonic(n):=apply("+",1/makelist(i,i,n))$ |
|||
first_greater_than_n(len):=block(i:1,result:[],while harmonic(i)<=len do (result:endcons(i,result),i:i+1),last(result)+1)$ |
|||
/* Test cases */ |
|||
/* First 20 harmonic numbers */ |
|||
makelist(harmonic(j),j,20); |
|||
/* First harmonic number that exceeds a positive integer from 1 to 5 */ |
|||
makelist(first_greater_than_n(k),k,5); |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[1,3/2,11/6,25/12,137/60,49/20,363/140,761/280,7129/2520,7381/2520,83711/27720,86021/27720,1145993/360360,1171733/360360,1195757/360360,2436559/720720,42142223/12252240,14274301/4084080,275295799/77597520,55835135/15519504] |
|||
[2,4,11,31,83] |
|||
</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |