Help Needed: Finding the First 10 Apocalyptic Numbers

  • Thread starter Thread starter Soff
  • Start date Start date
  • Tags Tags
    Numbers
AI Thread Summary
The discussion revolves around finding the first ten apocalyptic numbers, defined as numbers of the form 2^n that contain the digits 666. The initial Mathematica code provided fails to yield results due to incorrect usage of the Select function and pattern matching. The main issue is that the code checks for an exact match of the list {6, 6, 6} rather than allowing for additional digits before or after the sequence. To correct this, the use of a pure function with MatchQ is suggested, along with the introduction of BlankSequence (two underscores) to match patterns that include 666 among other digits. The final solution involves using Cases to find matches and returning the results as integers in a concise one-liner. This approach effectively identifies the desired apocalyptic numbers while optimizing performance by avoiding unnecessary recalculations.
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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top