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

Content added Content deleted
(Added Wren)
(Added AppleScript.)
Line 352: Line 352:
You too might have won $1000 with an answer of n = 1489
You too might have won $1000 with an answer of n = 1489
</pre>
</pre>

=={{header|AppleScript}}==
Like the other solutions here, this takes the linguistically confusing expression ''"the first position, &nbsp; p &nbsp; in the sequence where ā”‚a(n)/nā”‚ < 0.55 for all n > p"'' to mean the last position where the result's ''not'' < 0.55.

<lang applescript>on HC10000(ceiling)
script o
property lst : {1, 1}
property maxima : {}
end script
set p to missing value
set max to 0
set maxPos to 0
set power to 0
set x to end of o's lst
repeat with n from 3 to ceiling
set x to (item x of o's lst) + (item -x of o's lst)
set end of o's lst to x
set ann to x / n
if (ann is not less than 0.55) then set p to n
if (ann > max) then
set max to ann
set maxPos to n
end if
if (ann is 0.5) then
set power to power + 1
set end of o's maxima to {|<-powers->|:{power, power + 1}, n:maxPos, max:max}
set max to 0
end if
end repeat
return {p:p, maxima:o's maxima}
end HC10000

HC10000(2 ^ 20)</lang>

{{output}}

<lang applescript>{p:1489, maxima:{{|<-powers->|:{1, 2}, n:3, max:0.666666666667}, {|<-powers->|:{2, 3}, n:6, max:0.666666666667}, {|<-powers->|:{3, 4}, n:11, max:0.636363636364}, {|<-powers->|:{4, 5}, n:23, max:0.608695652174}, {|<-powers->|:{5, 6}, n:44, max:0.590909090909}, {|<-powers->|:{6, 7}, n:92, max:0.576086956522}, {|<-powers->|:{7, 8}, n:178, max:0.567415730337}, {|<-powers->|:{8, 9}, n:370, max:0.559459459459}, {|<-powers->|:{9, 10}, n:719, max:0.554937413074}, {|<-powers->|:{10, 11}, n:1487, max:0.550100874243}, {|<-powers->|:{11, 12}, n:2897, max:0.547462892648}, {|<-powers->|:{12, 13}, n:5969, max:0.544144747864}, {|<-powers->|:{13, 14}, n:11651, max:0.54244270878}, {|<-powers->|:{14, 15}, n:22223, max:0.540071097512}, {|<-powers->|:{15, 16}, n:45083, max:0.538784020584}, {|<-powers->|:{16, 17}, n:89516, max:0.537043657}, {|<-powers->|:{17, 18}, n:181385, max:0.536020067812}, {|<-powers->|:{18, 19}, n:353683, max:0.534645431078}, {|<-powers->|:{19, 20}, n:722589, max:0.533779229963}}}</lang>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==