Skip to content

Playing with the Beast Number with J

Vector 18:4, page 88

mathematics and statistics competitions and puzzles

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 88

Summary

In the end of the bible, there is the book of numbers.
We can make the numbers tell anything… but with J it is more entertaining!
It can be also the occasion to learn J through playing.
My purpose: the reader has fun with J.

Palindromes and Anti-palindromes

Viewed in its decimal form, the beast number: 666, nothing is blindingly obvious! but just it is a palindrome.

Let us calculate \(666^{666}\) and the number of digits when written in decimal form.

   b=:666x
   bp=:b^b
   digits=: #@":
   digits bp
1881

The number of digits in decimal form of \(666^{666}\) is still a palindrome!
Putting b in binary form

   ]bn=:#:b
1 0 1 0 0 1 1 0 1 0

It is anti-palindromic

   #bn NB. Counting the number of bits.
10

verifying it is an anti-palindrome:

   hbn=.5{.bn
   ^/(hbn,|.-.hbn)=bn
1

The other previous anti-palindromic numbers are: 2 10 12 38 42 52 56 142 150 170 178 204 212 232 240 542 558 598 614

So as not to use too much space, let us use transpose and read the numbers vertically

   |: #:2 10 12 38 42 52 56 142 150 170 178 204 212 232 240 542 558 598 614
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1
0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1
0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0
0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0
0 0 1 1 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1
1 1 0 1 1 0 0 1 1 1 1 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

To see better the anti-symmetric form of the beast number, let us put it under a chemical-like form (a la Kekule)

      0-1
     /   \
1-0-1     0-1-0
     \   /
      0-1

Can one guess why \(666^{666}\) represents the total destruction?

Think to world and anti-world…

The left middle is 1 and has "valence" 3 with 0s as atoms and the right middle is the contrary, a 0 with "valence" 3 with 1s as atoms.

The first "beastly palindromic prime" of the form 1 [0…0]666[0…0]1 is 16661
It is the 1928th prime:

   p:1927  NB. J works in origin 0
16661

But, 1+6+6+6+1=1+9+2+8

The next prime of this form has 13 zeros twice, that is:
1000000000000066600000000000001
Harvey Dubner determined that for the 7 first primes of this form the number of successive 0s is: 0, 13, 42, 506, 608, 2472, 2623.

If we write bp in binary form, it contains 6247 binary digits:

   $bbp=:#:bp
6247

how many times does the binary form bbp contain the beast number b?
Remember that bn was the binary form of b, then

   +/bn E. bbp
11

and 11 is 66%6

Note that 11, 111… are numbers derived from the beast number.

Other curiosities:

    b^6 NB. there are 6 6s in 666^6
87266061345623616

Note that in the previous sentence there are also 6 6s

In classical notation \(1^6 - 2^6 + 3^6\)

   -/(>:i.3)^6
666

   (+/6 6 6)*+/(6 1)^2
666

   (!6)*(+/(6 1)^2)%+/(6 2)^2
666

   +/(p:i.7)^2 NB. the sum of the squares of the 7 first primes
666

The sum of the 144 (= (6+6)*(6+6)) digits of Pi.

   12 12$p144 NB. 144 first decimals of Pi.
1 4 1 5 9 2 6 5 3 5 8 9
7 9 3 2 3 8 4 6 2 6 4 3
3 8 3 2 7 9 5 0 2 8 8 4
1 9 7 1 6 9 3 9 9 3 7 5
1 0 5 8 2 0 9 7 4 9 4 4
5 9 2 3 0 7 8 1 6 4 0 6
2 8 6 2 0 8 9 9 8 6 2 8
0 3 4 8 2 5 3 4 2 1 1 7
0 6 7 9 8 2 1 4 8 0 8 6
5 1 3 2 8 2 3 0 6 6 4 7
0 9 3 8 4 4 6 0 9 5 5 0
5 8 2 2 3 1 7 2 5 3 5 9

   +/p144
666

1998 is a multiple of the beast number: it is 3 times b.

We are the privileged guys who have known 2 successive palindromic years i.e. 1991 and 2002 containing a Beast year: 1998. (And also exceptionally a Leap year 2000, that is also a passage into a new millennium and century).

    ∇ Z←LP X
[1]   Z←≠/0=4 100 400 4000|X
    ∇

(Note that ≠ can be replaced here by -)
(A year is alternatively leap or not if it is divisible by 4, 100, 400, 4000)
(1900 was not a leap year, 2000 is). J version below.

   lp=:3 : '-.@=/0=4 100 400 4000|y.'

(Note that -.@= can be simplified by ~: )

   dif=: 3 : '(1}. y.) - _1}. y.'
   ]an=:4 2 $ 1991 2002 2992 3003 3993 4004 4994 5005
1991 2002
2992 3003
3993 4004
4994 5005
   ,dif   "0 1 an
11 11 11 11

Those living in these intervals can hope to see two successive palindromic years. The others have to wait 110 years!

   dif 2002 2112
110

In the early years (before 1000) you could see several!

   dif 666 676 686 696 707 717
10 10 10 11 10

Frank Fiederer points out that the age of the United States in 1998 (which is 3 times the Beast number) is also related to 666 since

   (1998-1776)=666%3
1

Yet another property on 1998 related to 666 by Monte Zerger.
If we associate 3 with the letter A, 6 with the letter B, 9 with the letter C…
The sum of the letters of the year NINETEEN NINETY EIGHT is equal to 666

NB. The letter A is at the index 65.
   +/3*(_64+a.i.'NINETEENNINETYEIGHT')
666

This digression on 1998 is just to point out that I intentionally wrote my 2nd paper on the Beast number in the Beast year 1998.

666 is the sum of two successive palindromic primes:

Successive palindromic primes: 2, 3, 5, 7, 11, 101, 131, 151, 181, 191, 313, 353, etc…

   +/313 353
666

The triplet (216, 630, 666) is a Pythagorean triplet:

   (6*6*6)^ 1 2
216 46656
   (666-6*6) ^1 2
630 396900
   666^2
443556
   +/(216 630)^2
443556
   b^2 3
443556 295408296

Defining Sk(n) the sum of the kth powers of the digits of n
We have S1(666)+S3(666)=666

   s=:6 6 6
   (+/s)++/s^3
666

We have also S3(666^2)+S1(666^3)=666
In other words: the sum of the cubes of the digits of the square of 666 plus the sum of the digits of the cube of 666 is equal to 666.

   (+/(4 4 3 5 5 6)^3)+(2+9+5+4+0+8+2+9+6)
666

Proving: let us calculate the number of digits of b^2 and b^3

   ]d2=:digits b^2
6
   ]d3=:digits b^3
9
   (+/(d3$10)#:b^3) ++/((d2$10)#:b^2)^3
666

Another number having this property is 2583:

   c=:2583x
   d2=:digits c^2
   d3=:digits c^3
   (+/(d3$10)#:c^3) ++/((d2$10)#:c^2)^3
2583

By P. De Geest we have also S1(666^47)=S1(666^51)=666

   d47=:digits b^47[d51=:digits b^51
   +/(d47$10)#:b^47
666
   +/(d51$10)#:b^51
666

Note that: (4+7)*(5+1)=66

P. De Geest and G. L. Honaker Jr. have found the following:
If we denote by SP(n) the sum of first n palindromic primes,
Then S3(SP(666)) is equal to 3 times 666
Note that 3 and 666 appear on both sides of the equation.
Here is a function that calculates the n first palindromic primes.

   palp=: 3 : 0
l=:0$0[i=:0
while. y. > $l do.
p=:x: p:i
i=:i+1
if. p= x: ". |. ": p do.
l=:l,p
end.
end.
)
t=:palp 111
   +/t  NB. The sum SP(111)
4641020

The function calculates easily the 113 first ones but spends a long time to find the 114th, then I abandoned to verify the above formula.
Challenge: write a function which proves that S3(SP(666)) = 3 * 666
Definition: two consecutive integers having the same sum of prime factors are called Ruth-Aaron pairs.
By Carlos Rivera:20772199 is the smallest integer with the property that the sum of the prime factors of n and the sum of the prime factors of n+1 are both equal to 666.

   n=:20772199
   (+/q:n), +/q:n+1
666 666
   (q:n) ; q:n+1
+------------+-----------------+
|7 41 157 461|2 2 2 5 5 283 367|
+------------+-----------------+

Then (20772199, 2077220) is the smallest beastly Ruth-Aaron pair.

The sum of the 666 first primes contains 666:

   q:+/p:i.666
23 191 349
   191*349
66659

Three funny sums!

   +/1 2 3 4 567 89
666
   +/123 456 78 9
666
   +/9 87 6 543 21
666

A Smith number is an integer in which the sum of its digits is equal to the sum of the digits of its prime factors. 666 is a Smith number.

   q:666
2 3 3 37
   (+/6 6 6)=+/2 3 3 3 7
1

The sum of the 6 first Roman numerals is 666

   D=:500[C=:100[L=:50[X=:10[V=:5[I=:1
   +/D,C,L,X,V,I
666

A chronogram in English for 666 for instance is what you should do when you encounter the number 666: "Expect the Devil" (+/X,C,D,V,I,L).
(the value of the chronogram is the sum of the roman letters encountered in the sentence, U,V and I,J are considered the same letter).

The sum of the \(n\) first integers is named the nth triangular number
In classical notation: \(T(n)=n(n+1)/2\)
Then the 36th triangular number is 666

   +/>:i. */6 6
666

Definition: a repdigit is a number consisting of a single repeated non zero digit as 666 or 22 or 33.
In 1975, Balley and Weger proved (see J. Rec. Math, Vol. 8, No 2): that 666 is the largest triangular number that’s also a repdigit.

Definition: A polygonal number is a positive number of the form
\(P(k,n)=n((k-2)n+4-k)/2\)
(\(k=3\) gives the triangular numbers, \(k=4\) gives the squares, 5 gives the pentagonal numbers etc..) example: \(P(3,36)=666\)
If one arranges a group of people in a solid 3012529326318802-sided polygon with 666 people on each side, there will be a total of 666666666666666666666 person in all, or \(P(3010529326318802,666)=666666666666666666666\).
Let us verify:

   Polyg=: 3 : 0
:
p=:y.*(((x.-2)*y.)+4-x.)%2
)
  3 Polyg 36
666
   k=: 3010529326318802x
   k Polyg b
666666666666666666666

Want more?, here are some examples:

(2 Polyg 666);(3 Polyg 36);(46 Polyg 6);(223 Polyg 3);666 Polyg 2
+---+---+---+---+---+
|666|666|666|666|666|
+---+---+---+---+---+

   (3 Polyg 11);8925662618878671x Polyg 387
+--+---------------------+
|66|666666666666666666666|
+--+---------------------+
   4357298474945533769063180827886710239651418x Polyg 18
666666666666666666666666666666666666666666666
   65662037493023408516366262845136084572704293x Polyg 143
666666666666666666666666666666666666666666666666

I stop here the examples: there is surely an infinity of expressions all equal to 666 (or repdigitd of 6’s) but some ones are more equal (ly interesting) than the others!

The opposite of the golden ratio divided by 2 is equal to sin(666) and cos(6*6*6) in degrees:

   gr=:(>:5^ 0.5)%2  NB. Golden ratio
   -gr%2
_0.809017
   1 o.666*o.%180  NB. Sin 666 in degrees
_0.809017
   2 o. (*/6 6 6)*o.%180   NB. Cos (6*6*6) in degrees
_0.809017

Then the golden number can be written as
-(sin(666)+cos(6*6*6))

   -((1 o.666*o.%180)+2 o. (*/6 6 6)*o.%180)
1.61803
   gr
1.61803

The evil eyed numbers family
Considering the beastly evil eyed number which is 60606

   q:60606
2 3 3 7 13 37
   */2 3 3 37
666

Then 60606 contains 666, 60606 is equal to 7*13*666
60606 is a 7-gonal number:

   7 Polyg 156
60606

It can be put under the following form:

   (>:6) Polyg */(+/6 6)*>:(+/6 6)
60606

We have seen above that 666 was the sum of two successive palindromic primes
It is the same for 60606:

   (+/313 353), +/30203 30403
666 60606

60606+1 is a prime number.

   q: >: 60606
60607

The period length of the decimal expansion of 1/60607 is 60606
(challenge: write a J expression that proves it)

Patrick De Geest points out that 666666 is a palindrome both in base 10 and in hexadecimal, proving it:

hfd=:16&#.@('0123456789ABCDEF'&i.)^:_1
   hfd 666666
A2C2A

He also notes that in base 31 it is MBMB, which is like 666666 formed with two consecutive identical parts (MB). Perhaps MB = Multiple Beast? (666 666)

b31=:31&#.@('0123456789ABCDEFGHIJKLMNOPQRSTU'&i.)^:_1
   b31 666666
MBMB

As a gift, I give you the possibility to try with greater numbers: here are two functions I wrote 15 years ago in APL and I have translated them directly in J.
They give the possibility to transform a decimal to any base until a limited base L and the inverse.

CH=:'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop
qrstuvwxyz~ '
DFGREP=:3 : (':'; 'x. #. (CH i. y.)')
GREPFD=:3 : (':'; '(((x. DGTS y.)$x.)#:y.){CH')

The DGTS function calculates the numbers of digits necessary to represent a decimal number y. in base x.

DGTS=:3 : (':'; '>:<.x.^.y.+y.=0')

Let us try:

   31 GREPFD 666666
MBMB
   31 DFGREP 'MBMB'
666666

NB. Note that using GREPFD, you can’t use a base greater than 70

   $CH
70
   69 DFGREP 'Jz'
1378
   69 GREPFD 1378
Jz

Here are the APL functions:

    ∇ Z←X GREP Y;⎕IO
[1]   ⎕IO←0
[2]   Z←'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst
uvwxyz∊_@#'[((X DIGITS Y)⍴X)⊤Y]
    ∇
    ∇ Z←X DIGITS Y ;⎕IO
[1]   ⎕IO←0 ⋄ Z←1+⌊X⍟Y+Y=0
    ∇

A challenge: try to write both functions DFGREP and GREPFD in J that allow us to work on base > 62, at least until 66.
Better, write them to allow extended integers.

Still better, look at the elegant writing of dfh and hfd and also hex that allows us to make operations on hexadecimal numbers.

dfh=:16&#.@('0123456789ABCDEF'&i.)
hfd=:dfh ^:_1
hex=:&.dfh
   'AB' *hex 'CD'
88EF

NB. (in French 8 is pronounced as ‘OUI’=YES and read the result above!)
Still better I said: try to write DFGREP and GREPFD extended to 66 base, in this J style
We shall read carefully the ‘technical correspondence’ column of Vector
As a reward, here is the other APL function.

    ∇ Z←X DFGREP Y;⎕IO
[1]   ⎕IO←0
[2]   Z←X⊥'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop
qrstuvwxyz∊_@#'⍳Y
    ∇

A last one, just for fun:
If you assign 6*6 to A, B=A+1, etc…the sum of the letters of the following word is 666

   +/36+(_65+a.i.'SUPERSTITIOUS')
666

I could not find a better formula for the French equivalent word!

   +/<.3.25*(_64+a.i.'SUPERSTITIEUX')
666

But it looks like a fixing thing!
Another better one in French (after many tries!):

   +/66+((*/5 5)-a.i.'VOICI LE NOMBRE DE LA BETE')
666

Conclusion

We can make the numbers to tell all what we want!

Exercises

  1. Try to rewrite the functions of the text above in a more elegant form
  2. Defining Pi(n,d) as the d consecutive decimal digits of pi starting at the nth digit after the decimal point: proves that Pi(666,3)=7*7*7

       */666 3.66366366366366
    2440
    

    Prove that Pi(2440,3)=666 ⇔ Pi((666*3.66366366366…),3)=666 3. Theorem (found by Jud McCranie) every positive integer occurs as the period length of the reciprocal of some prime.
    Found in June 1998: The smallest prime p such that 1/p has the period 666 is 90365999773. Write a J expression to prove it.
    (from Simon Whitechapel) the beginning of the sequence of primes such that 1/p have the period p-1 is
    7, 17, 19, 23, 29, 47, 59, 61, 97, 109, 113, 131, 149, …
    The last one, 1/149 has a period 148.
    Verify that the sum of those digits is 666.
    If we build a 148 148 matrix which rows are composed of the decimal digits of 1/149, 2/149, 3/149….. 148/149, the result is a pseudo magic square in which every row and column sums to 666. 4. The alphmetic below has a unique solution: find it.

        SIX
        SIX
        SIX
    + BEAST
    -------
      SATAN
    
  3. Find starable fractions in which stars (representing multiplication) can be interspersed in both numerator and denominator to produce an expression that’s equal to the original fraction:

    Example:

    6*6*6
    ----   =   -----
    64676      6*46*76
    

References

[1] De certaines propriétés du nombre de la bête.
Michel J. Dumontier ‘Les Nouvelles d’APL’ N° 21 pp. 99-102

[2] De certaines propriétés du nombre de la bête (suite)
Michel J. Dumontier ‘Les Nouvelles d’APL’ N° 28 pp. 69-72

[3] The page of Mike Keith on the Number of the Beast :
http://users.aol.com/sbsj7gt/mike666.htm