Sleeping Beauty problem: Difference between revisions

→‎{{header|Excel}}: Added a draft for Excel LAMBDA
(→‎{{header|Excel}}: Added a draft for Excel LAMBDA)
Line 65:
Sleeping Beauty should estimate a credence of: 0.333253
</pre>
 
=={{header|Excel}}==
===LAMBDA===
 
Binding the name SLEEPINGB to the lambda expression below in the Excel Workbook Name Manager:
 
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])
 
{{Works with | Office 365 betas 2021}}
<lang lisp>SLEEPINGB
=LAMBDA(n,
LET(
headsWakes, LAMBDA(x,
IF(1 = x,
{1,1},
{0,2}
)
)(
RANDARRAY(n, 1, 0, 1, TRUE)
),
TUPLE(
SUM(INDEX(headsWakes, 0, 1))
)(
SUM(INDEX(headsWakes, 0, 2))
)
)
)</lang>
 
and also assuming that the name TUPLE is bound to the following generic lambda in the workbook's Name Manager:
 
<lang lisp>TUPLE
=LAMBDA(a,
LAMBDA(b,
CHOOSE({1,2}, a, b)
)
)</lang>
 
{{Out}}
 
The pair of values in cells B2 and C2 both result from the application of SLEEPINGB in B2.
 
The credence value is returned by the expression B2/C2 in cell D2.
 
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="4" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=SLEEPINGB(1000000)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
| C
| D
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="text-align:right; font-weight:bold" |
| style="font-weight:bold" | Heads
| style="font-weight:bold" | Wakenings
| style="font-weight:bold" | Credence
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; font-weight:bold" | Results
| style="background-color:#cbcefb;" | 500111
| 1499889
| 0.33343200730187367
|}
 
 
 
=={{header|Factor}}==
9,655

edits