| Bytes | Lang | Time | Link |
|---|---|---|---|
| 058 | Wolfram Language Mathematica | 190925T010854Z | att |
| 113 | Raku Perl 6 rakudo exact | 240803T190942Z | bb94 |
| 071 | Perl 5 MPOSIX=log2 M5.01 n | 190925T071233Z | Nahuel F |
| 025 | MATL | 190925T101721Z | Luis Men |
| 018 | 05AB1E | 190925T104717Z | Grimmy |
| 078 | JavaScript V8 | 190925T075730Z | Shieru A |
| 108 | Clean | 190925T004946Z | Οurous |
| 092 | Python 2 | 190925T004909Z | xnor |
Wolfram Language (Mathematica), 62 60 58 bytes
Denominator@Table[a=#~Rationalize~Abs[#-a]&@Log2@3,a=1;#]&
Raku (Perl 6) (rakudo) (exact), 113 bytes
{$/=(0,2);(grep {$1**$_>(my$d=min map {1/$_ max$_},((2 X**^$_)X*(⅔.FatRat**$_)))**$0&&($/=($_,$d))},1..*)[^$_]}
Raku (Perl 6) (rakudo) (approximate), 77 bytes
{$!=1;(grep {$!>(my$d=min ((^$_ X/$_)X+⅔.log2)>>.abs)&&($!=$d)},1..*)[^$_]}
Perl 5 (-MPOSIX=log2 -M5.01 -n), 73, 78, 71 bytes
Fixed following comment, may be improved...
-7 bytes thanks to Grimy
$o=abs$d-(0|.5+($d=log2 3)*++$;)/$;;$@=$o,$_-=say$;if!$@|$o<$@;$_&&redo
MATL, 27 25 bytes
1`@:@/Q3Zl-|X<hY<tdzG-}df
Explanation
1 % Push 1. This initiallizes the vector of distances
` % Do...while
@: % Range [1, 2, ..., k], where k is the iteration index, staring at 1
@/ % Divide by k, element-wise. Gives [1/k, 2/k, ..., 1]
Q % Add 1, element-wise. Gives [(k+1/k, (k+2)/k, ..., 2]
3Zl % Push log2(3)
-| % Absolute difference, element-wise
X< % Minimum
h % Concatenate with vector of previous distances
Y< % Cumulative minimum
t % Duplicate
dz % Consecutive differences, number of nonzeros. This tells how many
% times the cumulative minimum has decreased
G- % Subtract input n. This is the loop condition. 0 means we are done
} % Finally (execute on loop exit)
d % Consecutive differences (of the vector of cumulative differences)
f % Indices of nonzeros. This is the final result
% End. A new iteration is executed if the top of the stack is nonzero
% Implicit display
05AB1E, 19 18 bytes
µ¯ßNLN/3.²<αßDˆ›D–
µ # repeat until counter == input
¯ # push the global array
ß # get the minimum (let's call it M)
N # 1-based iteration count
L # range 1..N
N/ # divide each by N
3.² # log2(3)
< # -1
α # absolute difference with each element of the range
ß # get the minimum
Dˆ # add a copy to the global array
› # is M strictly greater than this new minimum?
D– # if true, print N
# implicit: if true, add 1 to the counter
JavaScript (V8), 81 80 78 bytes
-2 bytes thanks Arnauld!
n=>{for(d=g=1;w=Math.log2(3),w+=~(w*g-.5)/g,n--;g++)w*w<d?d=print(g)||w*w:n++}
Clean, 128 111 108 bytes
import StdEnv
c=ln 3.0/ln 2.0
?d=abs(toReal(toInt(c*d))/d-c)
$i=take i(iterate(\d=until((>)(?d)o?)inc d)1.0)
Should work up to the limits of Real's 64-bit double precision type.
Python 2, 92 bytes
E=k=input()
n=0
while k:
n+=1;e=abs((3.169925001442312*n-1)%2-1)/n
if e<E:print n;E=e;k-=1
Uses the constant 3.169925001442312 for \$2 \log_2(3)\$. I wasn't sure how many digits of accuracy are required, since the inaccuracy will break the sequence eventually, so I used the full float precision of 2 * numpy.log2(3).