cp's OEIS Frontend

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.

A161872 Smallest unhappy number in base n (or 0 if no unhappy numbers in the base).

Original entry on oeis.org

0, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 7, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
Offset: 2

Views

Author

Jud McCranie, Jun 20 2009

Keywords

Comments

All positive integers are happy numbers in base 2 and base 4; they are called "happy bases". There are no other happy bases < 500,000,000.

Crossrefs

Cf. A031177 (Unhappy numbers in base 10).

Programs

  • Mathematica
    Table[If[MemberQ[{2, 4}, n], 0, Block[{k = 2}, While[NestWhile[Total[IntegerDigits[#, n]^2] &, k, UnsameQ, All] == 1, k++]; k]], {n, 2, 105}] (* Michael De Vlieger, Nov 06 2018 *)
  • PARI
    A161872(n) = if((2==n)||(4==n),0, for(k=2, oo, my(visited = Map(), t = k); while(t!=1, if(mapisdefined(visited, t), return(k), mapput(visited, t, t)); t = vecsum(apply(d -> (d*d),digits(t,n)))))); \\ Antti Karttunen, Nov 06 2018