Help Needed: Finding the First 10 Apocalyptic Numbers

  • Thread starter Thread starter Soff
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary
SUMMARY

The discussion focuses on identifying the first ten apocalyptic numbers, defined as numbers of the form 2n that contain the digits 666. The original Mathematica code provided by the user was incorrect due to improper use of the MatchQ function. The corrected approach utilizes BlankSequence (two underscores) to match patterns, allowing for the identification of numbers containing 666 within other digits. The final solution efficiently returns the results as integers using the FromDigits function.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of number theory concepts, particularly powers of two
  • Knowledge of pattern matching in Mathematica
  • Basic experience with list manipulation in Mathematica
NEXT STEPS
  • Explore advanced pattern matching techniques in Mathematica
  • Learn about the performance implications of using SetDelayed in Mathematica
  • Investigate the use of Cases and FromDigits functions in Mathematica
  • Study the properties and applications of apocalyptic numbers in number theory
USEFUL FOR

Mathematica programmers, mathematicians, and enthusiasts interested in number theory and computational methods for identifying specific numerical patterns.

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?
 
Technology 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:

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
5K
Replies
1
Views
3K
Replies
2
Views
2K