Hofstadter-Conway $10,000 sequence: Difference between revisions
Hofstadter-Conway $10,000 sequence (view source)
Revision as of 18:51, 16 January 2024
, 4 months agoAdded Easylang
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Added Easylang) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 1,224:
Max in [2^18, 2^19]: 0.534645
Max in [2^19, 2^20]: 0.533779</pre>
=={{header|EasyLang}}==
{{trans|Go}}
<syntaxhighlight>
numfmt 4 0
a[] = [ 1 1 ]
x = 1
n = 2
mallow = 0
for p = 1 to 19
max = 0
nextPot = n * 2
while n < nextPot
n = len a[] + 1
x = a[x] + a[n - x]
a[] &= x
f = x / n
max = higher max f
if f >= 0.55
mallow = n
.
.
print "max between 2^" & p & " and 2^" & p + 1 & " was " & max
.
print "winning number " & mallow
</syntaxhighlight>
=={{header|EchoLisp}}==
Line 1,612 ⟶ 1,638:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Hofstadter-Conway_%2410%2C000_sequence}}
'''Solution'''
This is the function according to the definition. It is very inefficient:
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 01.png]]
If a sequence is desired, it is much better to store the already calculated terms:
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 02.png]]
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 03.png]]
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 04.png]]
'''Test case 1.''' Show the maxima of <math>\frac{A(n)}{n}</math> between successive powers of two up to 2<sup>20</sup>
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 05.png]]
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 06.png]]
'''Test case 2.''' compute the value of n that would have won the prize and confirm it is true for n up to 2<sup>20</sup>
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 07.png]]
[[File:Fōrmulæ - Hofstadter–Conway $10,000 sequence 08.png]]
=={{header|FutureBasic}}==
Line 3,685 ⟶ 3,733:
Mallows number is 1489 </pre>
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn main() {
mut a := [0, 1, 1] // ignore 0 element. work 1 based.
mut x := 1 // last number in list
Line 3,737 ⟶ 3,785:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
var limit = 1<<20 + 1
Line 3,839 ⟶ 3,887:
a rd 1 shl 20</syntaxhighlight>
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">int A(1 + 1<<20), N, Power2, WinningN;
real Max, Member;
[A(1):= 1; A(2):= 1;
N:= 3; Power2:= 2; Max:= 0.;
Text(0, " Range Maximum^m^j");
Format(1, 6);
repeat A(N):= A(A(N-1)) + A(N-A(N-1));
Member:= float(A(N)) / float(N);
if Member >= Max then Max:= Member;
if Member >= 0.55 then WinningN:= N;
if N & 1<<Power2 then
[Text(0, "2^^"); IntOut(0, Power2-1);
Text(0, " to 2^^"); IntOut(0, Power2);
ChOut(0, 9\tab\);
RlOut(0, Max);
CrLf(0);
Power2:= Power2+1;
Max:= 0.;
];
N:= N+1;
until N > 1<<20;
IntOut(0, WinningN);
Text(0, " is the winning position.^m^j");
]</syntaxhighlight>
{{out}}
<pre>
Range Maximum
2^1 to 2^2 0.666667
2^2 to 2^3 0.666667
2^3 to 2^4 0.636364
2^4 to 2^5 0.608696
2^5 to 2^6 0.590909
2^6 to 2^7 0.576087
2^7 to 2^8 0.567416
2^8 to 2^9 0.559459
2^9 to 2^10 0.554937
2^10 to 2^11 0.550101
2^11 to 2^12 0.547463
2^12 to 2^13 0.544145
2^13 to 2^14 0.542443
2^14 to 2^15 0.540071
2^15 to 2^16 0.538784
2^16 to 2^17 0.537044
2^17 to 2^18 0.536020
2^18 to 2^19 0.534645
2^19 to 2^20 0.533779
1489 is the winning position.
</pre>
=={{header|zkl}}==
|