Harmonic series: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (Added R.) |
|||
Line 1,054: | Line 1,054: | ||
9 : 4550 |
9 : 4550 |
||
10 : 12367</pre> |
10 : 12367</pre> |
||
=={{header|R}}== |
|||
The talk page helpfully points out that we can be remarkably lazy here. |
|||
<lang R>HofN <- function(n) sum(1/seq_len(n)) #Task 1 |
|||
H <- sapply(1:100000, HofN) |
|||
print(H[1:20]) #Task 2 |
|||
print(sapply(1:10, function(x) which.max(H > x))) #Task 3 and stretch</lang> |
|||
{{out}} |
|||
<pre>> print(H[1:20]) #Task 2 |
|||
[1] 1.000000 1.500000 1.833333 2.083333 2.283333 2.450000 2.592857 2.717857 2.828968 2.928968 3.019877 3.103211 3.180134 3.251562 |
|||
[15] 3.318229 3.380729 3.439553 3.495108 3.547740 3.597740 |
|||
> print(sapply(1:10, function(x) which.max(H > x))) #Task 3 and stretch |
|||
[1] 2 4 11 31 83 227 616 1674 4550 12367</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |