\documentclass[a4paper]{article}
\pagestyle{empty}         % no page numbers

% Title and author go into PDF (by hyperref pdfusetitle),
% but not actually displayed.
\title{A363758 Maximum Sum of Digits}
\author{Kevin Ryde}
\date{March 2024}

\usepackage[T1]{fontenc}  % T1 for accents, before babel
\usepackage{amsmath}
\usepackage[pdfusetitle,
            pdfsubject={OEIS A363758},
            pdfkeywords={OEIS, A363758, base 4/3, mean digit},
            pdflang={en}, % RFC3066 ISO639 code
            pdfborderstyle={/W 0},  % no border on hyperlinks
           ]{hyperref}

\usepackage{tikz}
\usetikzlibrary{calc}     % for ($(...)$) coordinate calculations
\tikzset{>=latex,         % arrowhead type
         font=\small}     % same as text, not the display \normalfont

% % Uncomment this to see a box around each page text width and height.
% \usepackage{fancybox}
% \fancypage{\setlength{\fboxsep}{0pt}\fbox}{}

% GP-DEFINE  read("OEIS-data.gp");
% GP-DEFINE  read("OEIS-data-wip.gp");
% GP-DEFINE  A363758 = OEIS_data_func("A363758",'bfile);
% GP-DEFINE  A363758_maxn = #OEIS_data("A363758",'bfile) - 1;
% GP-DEFINE  print("A363758_maxn = ",A363758_maxn);

% GP-DEFINE  mean(n) = A363758(n) / n;


%------------------------------------------------------------------------------
\begin{document}
\hfil {\large
       A363758 Maximum Sum of Digits}
\hfil

\vspace{.2ex}

\hfil {Kevin Ryde, March 2024}
\hfil

\newcommand\MyTightDots{.\kern.08em.\kern.08em.}

\vspace{\baselineskip}

\href{http://oeis.org/A363758}{A363758} is the maximum sum of digits
for an $n$ digit number in fractional base $4/3$.  The following is a
plot of $a(n) / n$ which is the mean digit in such a number.

\begin{center}
\begin{tikzpicture}
    [xscale=.0554,yscale=20,
     my x number/.style={inner xsep=.1em},
    ]
  \coordinate (y-min) at (0, 2.0);
  \coordinate (y-max) at (0, 2.43);

  % generated by gen-plot-mean.pl
  % skip initial terms 0,3/1,6/2,8/3
  \draw[line cap=butt] (4,0 |- y-max)--(4,9/4)--(5,9/4)--(5,12/5)--(6,12/5)
    --(6,13/6)--(7,13/6)--(7,15/7)--(8,15/7)--(8,17/8)--(9,17/8)--(9,19/9)
    --(10,19/9)--(10,22/10)--(11,22/10)--(11,24/11)--(12,24/11)--(12,26/12)
    --(13,26/12)--(13,28/13)--(14,28/13)--(14,30/14)--(15,30/14)--(15,32/15)
    --(16,32/15)--(16,33/16)--(17,33/16)--(17,36/17)--(18,36/17)--(18,37/18)
    --(19,37/18)--(19,40/19)--(20,40/19)--(20,42/20)--(21,42/20)--(21,44/21)
    --(22,44/21)--(22,46/22)--(23,46/22)--(23,48/23)--(24,48/23)--(24,50/24)
    --(25,50/24)--(25,52/25)--(26,52/25)--(26,54/26)--(27,54/26)--(27,56/27)
    --(28,56/27)--(28,57/28)--(29,57/28)--(29,60/29)--(30,60/29)--(30,62/30)
    --(31,62/30)--(31,65/31)--(32,65/31)--(32,67/32)--(33,67/32)--(33,70/33)
    --(34,70/33)--(34,71/34)--(35,71/34)--(35,73/35)--(36,73/35)--(36,75/36)
    --(37,75/36)--(37,77/37)--(38,77/37)--(38,80/38)--(39,80/38)--(39,83/39)
    --(40,83/39)--(40,84/40)--(41,84/40)--(41,87/41)--(42,87/41)--(42,90/42)
    --(43,90/42)--(43,93/43)--(44,93/43)--(44,94/44)--(45,94/44)--(45,96/45)
    --(46,96/45)--(46,98/46)--(47,98/46)--(47,101/47)--(48,101/47)--(48,104/48)
    --(49,104/48)--(49,106/49)--(50,106/49)--(50,108/50)--(51,108/50)
    --(51,109/51)--(52,109/51)--(52,112/52)--(53,112/52)--(53,115/53)
    --(54,115/53)--(54,117/54)--(55,117/54)--(55,120/55)--(56,120/55)
    --(56,122/56)--(57,122/56)--(57,123/57)--(58,123/57)--(58,126/58)
    --(59,126/58)--(59,129/59)--(60,129/59)--(60,131/60)--(61,131/60)
    --(61,133/61)--(62,133/61)--(62,134/62)--(63,134/62)--(63,137/63)
    --(64,137/63)--(64,139/64)--(65,139/64)--(65,141/65)--(66,141/65)
    --(66,144/66)--(67,144/66)--(67,146/67)--(68,146/67)--(68,149/68)
    --(69,149/68)--(69,151/69)--(70,151/69)--(70,153/70)--(71,153/70)
    --(71,156/71)--(72,156/71)--(72,158/72)--(73,158/72)--(73,161/73)
    --(74,161/73)--(74,164/74)--(75,164/74)--(75,165/75)--(76,165/75)
    --(76,168/76)--(77,168/76)--(77,171/77)--(78,171/77)--(78,173/78)
    --(79,173/78)--(79,175/79)--(80,175/79)--(80,177/80)--(81,177/80)
    --(81,180/81)--(82,180/81)--(82,181/82)--(83,181/82)--(83,184/83)
    --(84,184/83)--(84,187/84)--(85,187/84)--(85,190/85)--(86,190/85)
    --(86,191/86)--(87,191/86)--(87,193/87)--(88,193/87)--(88,195/88)
    --(89,195/88)--(89,197/89)--(90,197/89)--(90,200/90)--(91,200/90)
    --(91,203/91)--(92,203/91)--(92,204/92)--(93,204/92)--(93,207/93)
    --(94,207/93)--(94,210/94)--(95,210/94)--(95,213/95)--(96,213/95)
    --(96,214/96)--(97,214/96)--(97,215/97)--(98,215/97)--(98,218/98)
    --(99,218/98)--(99,220/99)--(100,220/99)--(100,222/100)--(101,222/100)
    --(101,225/101)--(102,225/101)--(102,227/102)--(103,227/102)--(103,229/103)
    --(104,229/103)--(104,232/104)--(105,232/104)--(105,235/105)--(106,235/105)
    --(106,238/106)--(107,238/106)--(107,241/107)--(108,241/107)--(108,242/108)
    --(109,242/108)--(109,245/109)--(110,245/109)--(110,248/110)--(111,248/110)
    --(111,251/111)--(112,251/111)--(112,254/112)--(113,254/112)--(113,256/113)
    --(114,256/113)--(114,259/114)--(115,259/114)--(115,262/115)--(116,262/115)
    --(116,265/116)--(117,265/116)--(117,268/117)--(118,268/117)--(118,271/118)
    --(119,271/118)--(119,274/119)--(120,274/119)--(120,277/120)--(121,277/120)
    --(121,279/121)--(122,279/121)--(122,280/122)--(123,280/122)--(123,281/123)
    --(124,281/123)--(124,284/124)--(125,284/124)--(125,285/125)--(126,285/125)
    --(126,288/126)--(127,288/126)--(127,291/127)--(128,291/127)--(128,292/128)
    --(129,292/128)--(129,294/129)--(130,294/129)--(130,297/130)--(131,297/130)
    --(131,300/131)--(132,300/131)--(132,303/132)--(133,303/132)--(133,304/133)
    --(134,304/133)--(134,307/134)--(135,307/134)--(135,309/135)--(136,309/135)
    --(136,312/136)--(137,312/136)--(137,313/137)--(138,313/137)--(138,315/138)
    --(139,315/138)--(139,316/139)--(140,316/139)--(140,319/140)--(141,319/140)
    --(141,321/141)--(142,321/141)--(142,324/142)--(143,324/142)--(143,326/143)
    --(144,326/143)--(144,329/144)--(145,329/144)--(145,331/145)--(146,331/145)
    --(146,334/146)--(147,334/146)--(147,337/147)--(148,337/147)--(148,339/148)
    --(149,339/148)--(149,342/149)--(150,342/149)--(150,343/150)--(151,343/150)
    --(151,345/151)--(152,345/151)--(152,347/152)--(153,347/152)--(153,350/153)
    --(154,350/153)--(154,352/154)--(155,352/154)--(155,354/155)--(156,354/155)
    --(156,356/156)--(157,356/156)--(157,359/157)--(158,359/157)--(158,361/158)
    --(159,361/158)--(159,363/159)--(160,363/159)--(160,366/160)--(161,366/160)
    --(161,369/161)--(162,369/161)--(162,372/162)--(163,372/162)--(163,373/163)
    --(164,373/163)--(164,374/164)--(165,374/164)--(165,376/165)--(166,376/165)
    --(166,379/166)--(167,379/166)--(167,380/167)--(168,380/167)--(168,383/168)
    --(169,383/168)--(169,384/169)--(170,384/169)--(170,387/170)--(171,387/170)
    --(171,389/171)--(172,389/171)--(172,392/172)--(173,392/172)--(173,394/173)
    --(174,394/173)--(174,397/174)--(175,397/174)--(175,399/175)--(176,399/175)
    --(176,400/176)--(177,400/176)--(177,402/177)--(178,402/177)--(178,404/178)
    --(179,404/178)--(179,407/179)--(180,407/179)--(180,409/180)--(181,409/180)
    --(181,411/181)--(182,411/181)--(182,414/182)--(183,414/182)--(183,417/183)
    --(184,417/183)--(184,419/184)--(185,419/184)--(185,421/185)--(186,421/185)
    --(186,424/186)--(187,424/186)--(187,427/187)--(188,427/187)--(188,429/188)
    --(189,429/188)--(189,430/189)--(190,430/189)--(190,432/190)--(191,432/190)
    --(191,434/191)--(192,434/191)--(192,436/192)--(193,436/192)--(193,439/193)
    --(194,439/193)--(194,442/194)--(195,442/194)--(195,445/195)--(196,445/195)
    --(196,447/196)--(197,447/196)--(197,449/197)--(198,449/197)--(198,452/198)
    --(199,452/198)--(199,453/199)--(200,453/199)--(200,456/200)--(201,456/200)
    --(201,459/201)--(202,459/201)--(202,462/202)--(203,462/202)--(203,464/203)
    --(204,464/203)--(204,467/204)--(205,467/204)--(205,468/205)--(206,468/205)
    --(206,469/206)--(207,469/206)--(207,472/207)--(208,472/207);
  \coordinate (x-min) at (0,0 |- y-min);
  \coordinate (x-max) at (208,0 |- y-min);
  % end generated

  % X axis
  \draw[dashed,->] (x-min) -- ($(x-max) + (0, 0)$)
    node[at end,above left,inner xsep=0pt,
         yshift=.8ex] {$n$};
  \coordinate (x-tick) at (0,-.012);
  \foreach \x in {4, 20, 40, ...,200} {
    \draw ($(\x,0) + (y-min)$) -- +(x-tick)
      +(.5,0) node[at end,below] {\x};
  }

  % Y axis
  \draw[->] (y-min) -- ($(y-max) + (0,.02)$)
    node[at end,below right,xshift=3em,yshift=-2ex]
        {$\dfrac{a(n)}{n}$ \hskip.2em mean digit};
  \coordinate (y-tick) at (-2,0);
  \foreach \y in {2.0, 2.1, 2.2, 2.3, 2.4} {
    \draw (0,\y) -- +(y-tick)
      node[at end,left=.1em,inner xsep=0pt] {\y};
  }

  \coordinate (peak) at (120.5, 2.315);
  \draw[dashed] ($(peak) +(-5,.023)$) .. controls +(-45:.01) and +(135:.01) .. (peak)
    node[at start,above,align=left]
        {$n{=}120$ \\ $2.308 \MyTightDots$};

\end{tikzpicture}
\end{center}

\smallskip

Initial terms $a(1 \MyTightDots 3)$ are omitted.  Their means are
$3, \, 3, \, 2{+}\tfrac23$.
% GP-Test  apply(mean,[1..3]) == [3, 3, 2+2/3]

The peak (so far) in the middle of the plot is at
  $n {=}
% GP-CONSTANT peak_n
 120
% GP-END
$
which has sum of digits
  $a(n) = 277$
% GP-Test  A363758(peak_n) == 277
for mean
  $277/120 = 2.308 \MyTightDots$.
% GP-Test  mean(peak_n) == 277/120
% GP-Test  floor(mean(peak_n)*1000) == 2308
% GP-Test  my(m=vecmax(apply(mean,[6..A363758_maxn]))); \
% GP-Test  m == 277/120 && \
% GP-Test  select(n->mean(n)==m, [4..A363758_maxn]) == \
% GP-Test    [peak_n]

\bigskip

If digits were random $0,1,2,3$ then the mean would be $1.5$.  Some
experiments with small $n$ suggest this is roughly so taken over all
numbers of $n$ digits.

The numerical maximum number with $n$ digits uses only $1,2,3$ (and
ends $3$).  If those were random then their mean would be $2$.  Some
experiments suggest this is roughly so for small $n$.

The plot up to the middle peak $n{=}120$ might have looked like
continuing to grow, but beyond that the means drift down (so far)
towards about $2.28$.
% end at n=200 a(n)=456 is mean 456/200 = 2.28
% GP-Test  mean(200) == 456/200
% GP-Test  mean(200) == 228/100
%
% n=207 very close to 2.28
% GP-Test  mean(207) == 472/207
% GP-Test  mean(207) == 228/100 + 1/5175
%
% for(n=A363758_maxn-20,A363758_maxn, \
%   print(mean(n)*1.0));

%------------------------------------------------------------------------------
\end{document}
