1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Beast Numbers

  1. May 26, 2007 #1

    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?
  2. jcsd
  3. May 26, 2007 #2
    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 refered to.

    Now, notice that the second argument of Select should be a function. If you execute:
    Code (Text):

    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 (Text):

    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 (Text):

    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:

    It might be nice to return the results as integers, rather then lists, and write the program in one line:

    Code (Text):
    Last edited: May 26, 2007
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Beast Numbers
  1. Reverse the number (Replies: 0)

  2. Random numbers (Replies: 13)

  3. Truncating a number (Replies: 4)

  4. Number of digit (Replies: 2)