Talk:Average loop length: Difference between revisions

From Rosetta Code
Content added Content deleted
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Analytical formula?==
==Analytical formula?==
Hi, the task needs the analytical formula to be stated as part of the task description rather than leaving it to be discovered. --[[User:Paddy3118|Paddy3118]] 15:53, 4 January 2013 (UTC)
Hi, the task needs the analytical formula to be stated as part of the task description rather than leaving it to be discovered. --[[User:Paddy3118|Paddy3118]] 15:53, 4 January 2013 (UTC)
: I've watched the lecture; the problem in question is in the last 10 minutes and is only mentioned in passing. IIRC, it is at about 1:32:00 (and I forgot to note it down). If you've got the time though, it's ''well'' worth watching the whole thing, and the mathematics involved is extremely simple (yet talks about some very interesting properties of sequences). –[[User:Dkf|Donal Fellows]] 10:54, 9 January 2013 (UTC)


== Is there an relation to 100 prisoners? ==
:Let me try:
:<math>P_k</math> is the probability for a sequence of length k to loop on the k-th term
:We have <math>P_1 = 1</math>.
:For k>1,
:<math>P_k = \frac{N (N-1)^{k-2}}{N^k} = \frac{(N-1)^{k-2}}{N^{k-1}} = \frac{1}{N}(1 - \frac{1}
{N})^{k-2}</math>
:The average length it then:
:<math>\langle L \rangle = \sum_{k=1}^{N} P_k\, k = 1 + \sum_{k=2}^{N} k\frac{(N-1)^{k-2}}{N^{k-1}} = 1 + \frac{1}{N} \sum_{k=2}^{N} k (1 - \frac{1}{N})^{k-2}</math>


[[http://rosettacode.org/wiki/100_prisoners 100 prisoners]]<BR>
:I doubt this is the correct formula as it does not give the same numerical result as the Perl6 code. It's also very different as it does not have any factorial in it. I must have missed something.
Here is the the task, to calculate the propability of finding a cycle/reoccurence of n?
:--[[User:Grondilu|Grondilu]] 17:27, 4 January 2013 (UTC)
In 100 prisoners you start with number n and hope to find n again.
--[[user Horst.h|Horst.h]] [[User:Horst.h|Horst.h]] ([[User talk:Horst.h|talk]]) 08:26, 6 February 2020 (UTC)
: Sure, in the sense that they share features -- both tasks deal with permutations (and permutations of length 100, at that). But they are also different tasks, and the solutions are different. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 17:40, 6 February 2020 (UTC)


== Syntax errors: regarding "as" at lines 39 and 43 ==
:O yeah I understood my mistake. <math>P_k = \frac{N!}{(N-k)!N^k}</math> or something like that because you don't only want to avoid repeating the first term before the k-th, you also want to avoid all preceding ones.

:--[[User:Grondilu|Grondilu]] 18:50, 4 January 2013 (UTC)
Hi;

wren_cli average_loop_length.wren
[./average_loop_length line 39] Error at 'as': Expect variable name.
[./average_loop_length line 43] Error at 'as': Expected expression.

Thanks,
Retired_Build_Engineer

:Yeah, the problem there is that, when I wrote this example, Wren was only at version 0.2.0 and I hadn't yet added the C-like Fmt.print statement. 'as' became a keyword in version 0.4.0 and so can no longer be used as an ordinary variable name, hence the error message. Anyway I've changed it now though note that, as the output is random, you'll get a different table each time you run it. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 07:01, 2 September 2023 (UTC)

Latest revision as of 07:01, 2 September 2023

Analytical formula?

Hi, the task needs the analytical formula to be stated as part of the task description rather than leaving it to be discovered. --Paddy3118 15:53, 4 January 2013 (UTC)

I've watched the lecture; the problem in question is in the last 10 minutes and is only mentioned in passing. IIRC, it is at about 1:32:00 (and I forgot to note it down). If you've got the time though, it's well worth watching the whole thing, and the mathematics involved is extremely simple (yet talks about some very interesting properties of sequences). –Donal Fellows 10:54, 9 January 2013 (UTC)

Is there an relation to 100 prisoners?

[100 prisoners]
Here is the the task, to calculate the propability of finding a cycle/reoccurence of n? In 100 prisoners you start with number n and hope to find n again. --Horst.h Horst.h (talk) 08:26, 6 February 2020 (UTC)

Sure, in the sense that they share features -- both tasks deal with permutations (and permutations of length 100, at that). But they are also different tasks, and the solutions are different. --Rdm (talk) 17:40, 6 February 2020 (UTC)

Syntax errors: regarding "as" at lines 39 and 43

Hi;

wren_cli average_loop_length.wren [./average_loop_length line 39] Error at 'as': Expect variable name. [./average_loop_length line 43] Error at 'as': Expected expression.

Thanks, Retired_Build_Engineer

Yeah, the problem there is that, when I wrote this example, Wren was only at version 0.2.0 and I hadn't yet added the C-like Fmt.print statement. 'as' became a keyword in version 0.4.0 and so can no longer be used as an ordinary variable name, hence the error message. Anyway I've changed it now though note that, as the output is random, you'll get a different table each time you run it. --PureFox (talk) 07:01, 2 September 2023 (UTC)