Hofstadter-Conway $10,000 sequence: Difference between revisions

Added Easylang
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}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
This is the function according to the definition. It is very inefficient:
In '''[https://formulae.org/?example=Hofstadter-Conway_%2410%2C000_sequence this]''' page you can see the program(s) related to this task and their results.
 
[[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="ecmascriptwren">import "./fmt" for Fmt
 
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}}==
2,060

edits