This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A074989 #33 Mar 31 2021 22:27:58 %S A074989 0,0,1,2,3,3,2,1,0,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6, %T A074989 7,8,9,10,11,12,13,14,15,16,17,18,18,17,16,15,14,13,12,11,10,9,8,7,6, %U A074989 5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 %N A074989 Distance from n to nearest cube. %C A074989 a(n)=0 when n is a cube; between zeros local maxima are of form 3/2 k(k-1). %H A074989 Reinhard Zumkeller, <a href="/A074989/b074989.txt">Table of n, a(n) for n = 0..10000</a> %H A074989 <a href="/index/Di#distance_to_the_nearest">Index entries for sequences related to distance to nearest element of some set</a> %e A074989 a(3) = 2 because the nearest cube to 3 is 1 and distance from 3 to 1 is 2. %p A074989 A074989 := proc(n) local iscbr ; iroot(n,3,'iscbr') ; if iscbr then 0; else iscbr := floor(n^(1/3)) ; min((iscbr+1)^3-n, n-iscbr^3) ; end if; end proc; # _R. J. Mathar_, Nov 01 2009 %t A074989 dnc[n_]:=Module[{cr=Surd[n,3]},Min[n-Floor[cr]^3,Ceiling[cr]^3-n]]; Array[ dnc,90,0] (* _Harvey P. Dale_, Jan 24 2015 *) %o A074989 (Haskell) %o A074989 a074989 0 = 0 %o A074989 a074989 n = min (n - last xs) (head ys - n) where %o A074989 (xs,ys) = span (< n) a000578_list %o A074989 -- _Reinhard Zumkeller_, Nov 28 2011 %o A074989 (Python) %o A074989 from sympy import integer_nthroot %o A074989 def A074989(n): %o A074989 a = integer_nthroot(n,3)[0] %o A074989 return min(n-a**3,(a+1)**3-n) # _Chai Wah Wu_, Mar 31 2021 %Y A074989 Cf. A053188 (distance from n to nearest square). %Y A074989 Cf. A201053, A000578. %K A074989 nonn %O A074989 0,4 %A A074989 _Zak Seidov_, Oct 02 2002 %E A074989 a(0) added and offset changed by _Reinhard Zumkeller_, Nov 28 2011