Post Reply 
[VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math"
02-16-2021, 09:56 AM
Post: #9
RE: [VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math...
Free42 code for challenges 1,2 and 3:

VA#1: average nr of random numbers in X runs to sum over Y

e.g. 2 ENTER 100000 XEQ"VA1" -> 4.67827

00 { 39-Byte Prgm }
01▸LBL "VA1"
02 LSTO "X"
03 LSTO "C"
04 SIGN
05 SEED
06 CLX
07 STO ST Z
08▸LBL 02
09 ISG ST Z
10 X<>Y
11 RAN
12 +
13 X≤Y?
14 GTO 02
15 CLX
16 DSE "C"
17 GTO 02
18 R^
19 RCL÷ "X"
20 END

results identical to robve's post. I would say that for 'larger' n, the limit is 2(n+1/3)..

00 { 73-Byte Prgm }
01▸LBL "VA2"
02 1
03 LSTO "P" @ term
04 CLX
05 LSTO "S" @ sum
06 2
07 XEQ 14
08 3
09▸LBL 03
10 XEQ "P?"
11 X=0?
12 GTO 00
13 R↓
14 XEQ 14
15 X=Y?
16 RTN
17 R↓
18▸LBL 00
19 R↓
20 2
21 +
22 GTO 03
23▸LBL 14
24 RCL "P"
25 2021
26 RCL ST Z
27 +
28 ÷
29 ×
30 STO "P"
31 X<> ST L
32 X<> "S"
33 STO+ "S"
34 RCL "S"
35 END

The P? primality testing program returns X and 0 when not prime, 1 when prime. You may use eg

00 { 114-Byte Prgm }
01>LBL "P?"
02 ENTER
03 STO ST Z
04 2
05 X=Y?
06 GTO 01
07 X>Y?
08 SIGN
09 MOD
10 X=0?
11 RTN
12 CLX
13 3
14 X=Y?
15 GTO 01
16 MOD
17 X=0?
18 RTN
19 CLX
20 5
21 X=Y?
22 GTO 01
23 MOD
24 X=0?
25 RTN
26 CLX
27 7
28>LBL 03
29 X^2
30 X>Y?
31 GTO 01
32 SQRT
33 MOD
34 X=0?
35 RTN
36 CLX
37 4
38 LASTX
39 +
40 MOD
41 X=0?
42 RTN
43 CLX
44 2
45 LASTX
46 +
47 MOD
48 X=0?
49 RTN
50 CLX
51 4
52 LASTX
53 +
54 MOD
55 X=0?
56 RTN
57 CLX
58 2
59 LASTX
60 +
61 MOD
62 X=0?
63 RTN
64 CLX
65 4
66 LASTX
67 +
68 MOD
69 X=0?
70 RTN
71 CLX
72 6
73 LASTX
74 +
75 MOD
76 X=0?
77 RTN
78 CLX
79 2
80 LASTX
81 +
82 MOD
83 X=0?
84 RTN
85 CLX
86 6
87 LASTX
88 +
89 GTO 03
90>LBL 01
91 SIGN
92 END

@robve: you made the same mistake I did at first.. read the formula carefully, the nominator goes to pk-1 and the denominator to pk.

The sum converges quickly to 4.948045522...E-04, which is exactly 1/2021. Why? I'm sure Valentin will enlighten us in a few days ;-)

VA#3: integral
Program to be used with INTEG

00 { 37-Byte Prgm }
01▸LBL "VA3"
02 MVAR "X"
03 1.25
04 SQRT
05 1.5
06 +
07 RCL- "X"
08 LN
09 GAMMA
10 RCL "X"
11 LN
12 GAMMA
13 RCL+ ST Y
14 ÷
15 END

Making use of the fact that φ^2 = φ+1
Same observations as J-F.. though the fact that it's easy to see what the value is, does not explain (to me) why it converges so quickly.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenge #25 "San Valentin's Special: Weird Math... - Werner - 02-16-2021 09:56 AM



User(s) browsing this thread: 5 Guest(s)