More Samples
{
According to  Clifford A. Pickover "Apocalyptic Number" is a number such that 
the number is 2 to the power of i, where i > 1 and the number contains "666". 
The following number is the first power of 2 to exhibit this feature 
(i = 157, i.e. 2**157):

182687704666362864775460604089535377456991567872
         ^^^   
         
Clifford also asked the following questions:
Q1: are there any other apocalyptic powers for higher powers than 157.
Q2: are there any "double apocalyptic powers", i.e. numbers which contains
    six 6's in a row.

We can easily solve the problem using the code below.

We can do even better, we can define our own numbers. For example, we can 
define "weird" number as a number which is 2 to the power of i, i>1, such 
that the number contains the word "weird". This, of course, assumes the number
is not printed out in decimal notation (a silent assumption by Mr. Picover). 

In principle, you should be able to find any string, such as your name,
but you must be patient, especially if your name is long. 

Example queries:

To check all powers of two up to 2**1500000 and find the string 666666 in 
a decimal number, run the query

    FindStringInDecNumber('*666666',150000)

This will find thousends of "double apocalyptical" numbers (3043) in about 
25 minutes running on a modest Athlon XP 1600+.

To find any alpha numerical string, we cannot use decimal number representation.
Here we use base 36, which conveniently contains the whole alphabet and all digits.

For example, in order to find all "weird" numbers up to 2 to the power of 100000, 
run the following query:

    FindStringInBase36Number('*weird',100000)  

This should prove that the first "weird" number is 2**24687

By modifying the above queries, you can discover many other interresting numbers 
and ensure your deserving place in annals of mathematical history.

See if you can prove the following shocking discoveries:
The first moronic number is 2 to the power of 26721 (contains "moron")
The first "stupid" number is 2 to the power of 148032.

You can also modify the code to use hexadecimal numbers (i.e. numbers of base 16)
and find "DEAD" numbers or even the more elusive doubly dead "DEADDEAD" numbers.

Note:
We don't really bother to printout the numbers we find, but it is simple to modify
the code below to do that if you desire to do so.

It is important this program is compiled with (simple) garbage collection enabled,
as the numbers we are dealing here with are enormous.

}


proc FindStringInDecNumber(sin:<S,n:<I[1..]) iff
    x:.L & x:= 2 & count :.I & count := 0 & FindStringInBaseNumber(sin,x,1,n,count,10) & 
    Print('\nFound occurences:',count)

proc FindStringInBase36Number(sin:<S,n:<I[1..]) iff
    x:.L & x:= 2 & count :.I & count := 0 & FindStringInBaseNumber(sin,x,1,n,count,36) & 
    Print('\nFound occurences:',count)

local proc FindStringInBaseNumber(sin:<S,x:.L,n:<I,nmax:<I,count:.I,base:<I) iff
    if n <= nmax then
        CheckBaseNumber(sin,x,n,count,base) & 
        x:=x*2 & FindStringInBaseNumber(sin,x,n+1,nmax,count,base) 
    end

local proc CheckBaseNumber(sin:<S,x:<L,n:<I,count:.I,base:<I) iff 
    Print('\r', n) & 
    RtlLtoSx(x,base,s) & //convert the number to string
    if sin in s then count := count+1 & Print(' FOUND\n') end








This page was created by F1toHTML