Function Repository Resource:

# HappyNumberQ

Test whether an integer is a happy number

Contributed by: Sander Huisman
 ResourceFunction["HappyNumberQ"][n] tests whether repeatedly summing up the square of the digits of n reaches 1. ResourceFunction["HappyNumberQ"][n,b] considers the integer digits of n in base b. ResourceFunction["HappyNumberQ"][n,b,p] raises the digits to the power p.

## Details and Options

The base b has to be at least 2.
The power p has to be at least 1.

## Examples

### Basic Examples (2)

Test whether 19 is a happy number:

 In[1]:=
 Out[1]=

Test whether 1579 is a happy number based on its digits in base 7:

 In[2]:=
 Out[2]=

### Scope (1)

Cube the numbers rather than squaring them:

 In[3]:=
 Out[3]=

### Properties and Relations (1)

In base 2, all numbers are happy:

 In[4]:=
 Out[4]=

### Possible Issues (2)

 In[5]:=
 Out[5]=

Checking for higher powers can take a lot more time:

 In[6]:=
 Out[6]=

### Neat Examples (2)

Find numbers that are happy in many bases:

 In[7]:=
 Out[11]=

Find happy numbers that are also prime:

 In[12]:=
 Out[12]=

SHuisman

## Requirements

Wolfram Language 11.3 (March 2018) or above

## Version History

• 1.0.0 – 10 May 2019