Q041

Pandigital prime

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.

What is the largest n-digit pandigital prime that exists?


In [ ]:

Q042

Coded triangle numbers

The nth term of the sequence of triangle numbers is given by, $t^n = 1/2 n(n+1)$; so the first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = $t_{10}$. If the word value is a triangle number then we shall call the word a triangle word.

Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?


In [1]:
!wget 'https://projecteuler.net/project/resources/p042_words.txt'


--2017-09-24 17:48:19--  https://projecteuler.net/project/resources/p042_words.txt
Resolving projecteuler.net (projecteuler.net)... 185.119.173.194
Connecting to projecteuler.net (projecteuler.net)|185.119.173.194|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16345 (16K) [text/plain]
Saving to: ‘p042_words.txt’

100%[======================================>] 16,345      60.0KB/s   in 0.3s   

2017-09-24 17:48:21 (60.0 KB/s) - ‘p042_words.txt’ saved [16345/16345]


In [29]:
f=open('p042_words.txt')
words=f.read().replace('\"','').split(',')
def wordToNumberSum(s):
    return sum([ord(i)-ord('A')+1 for i in s])
numbersum = map(wordToNumberSum,words)

def triangularLessThanN(n):
    i=1
    triangular=[]
    while i*(i+1)/2 < n:
        triangular.append(i*(i+1)/2)
        i+=1
    return triangular
triangular = triangularLessThanN(max(numbersum))
count=0
for i in numbersum:
    for j in triangular:
        if i == j:
            count+=1
print count


162

Q043

Sub-string divisibility

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.

Let $d_1$ be the 1st digit, $d_2$ be the 2nd digit, and so on. In this way, we note the following:

$d_2 d_3 d_4$=406 is divisible by 2

$d_3 d_4 d_5$=063 is divisible by 3

$d_4 d_5 d_6$=635 is divisible by 5

$d_5 d_6 d_7$=357 is divisible by 7

$d_6 d_7 d_8$=572 is divisible by 11

$d_7 d_8 d_9$=728 is divisible by 13

$d_8 d_9 d_{10}$=289 is divisible by 17

Find the sum of all 0 to 9 pandigital numbers with this property.


In [ ]: