Help Needed: Finding the First 10 Apocalyptic Numbers

  • Thread starter Thread starter Soff
  • Start date Start date
  • Tags Tags
    Numbers
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
Soff
Messages
36
Reaction score
0
Hello!

I got a problem:

I want to find out the first ten apocalyptical numbers.By definition, a number of the form 2^n that contains the digits 666 (i.e., the beast number) is called an apocalyptic number.

I tried to write a short program with mathematica:

l := Table[2^n, {n, 1, 1000}]
a := IntegerDigits[l]
Select[a, MatchQ[a, {6, 6, 6}], 10]

However, the result is always {}
What's wrong with the program above?

Can somebody give me an advice?
 
Physics news on Phys.org
First a general comment: in this case the use of SetDelayed := will cause reduced performance, because it is unnecessary to recalculate the table each time it is referred to.

Now, notice that the second argument of Select should be a function. If you execute:
Code:
MatchQ[a,{6,6,6}]

It returns False, because a (a table of list of digits of integers) does not literally match {6,6,6}. What we really want is a function that compares each element of a with {6,6,6}, which could be given as:
Code:
l := Table[2^n, {n, 1, 1000}]
a := IntegerDigits[l]
Select[a, MatchQ[#, {6, 6, 6}]&, 10]

(the # is the formal parameter of the pure function and the & delimits its body).

Now executing the code I gave still returns the empty set, and this is because we are only checking for numbers that match 666, not those of the form:

*digits* 666 *more digits*

To do this in mathematica we use a BlankSequence (two underscores). This works to find your numbers:
Code:
l = Table[2^n, {n, 1, 1000}];
a = IntegerDigits[l];
Select[a, MatchQ[#, {__,6, 6, 6,__}]&, 10]

but since we are matching a pattern rather then testing a boolean, it makes more sense to use Cases:

l = Table[2^n, {n, 1, 1000}];
a = IntegerDigits[l];
Take[Cases[a, {__,6, 6, 6,__}], 10]
It might be nice to return the results as integers, rather then lists, and write the program in one line:

Code:
FromDigits/@Take[Cases[IntegerDigits@Table[2^n,{n,1,2000}],{__,6,6,6,__}],10]
 
Last edited: