# Pandigital

## Pandigitial primes

I got a fun little question from Jean-Marie by email the other day. With the disclaimer that I don’t really have the time to solve that many puzzles and therefore probably wont be able to give you a solution to puzzles like this one. This one triggered my curiosity and I managed to find a rather cure solution.

Therefore I will post it to you all and let you wonder a bit about it. If you find the solution feel free to post it in the comments.

The question is simple:

Find all the primes that contain 9 different digits (0 excluded).

Good luck ðŸ™‚

Posted by Kristian in Math, 3 comments

## Project Euler 104: Finding Fibonacci numbers for which the first and last nine digits are pandigital.

Problem 104 of Project Euler is squeezed in between three related problems, but that should not keep us from actually solving it. The problem reads

The Fibonacci sequence is defined by the recurrence relation:

FnÂ = Fn-1Â + Fn-2, where F1Â = 1 and F2Â = 1.

It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.

Given that FkÂ is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, findÂ k.

Posted by Kristian in Project Euler, 14 comments

## Project Euler 43: Find the sum of all pandigital numbers with an unusual sub-string divisibility property

When I first saw pandigital numbers I thought it was just a curious thing that we would visit once. I was wrong as Problem 42 of Project Euler is also about a special group of pandigital numbers. The problem reads

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 d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:

• d2d3d4=406 is divisible by 2
• d3d4d5=063 is divisible by 3
• d4d5d6=635 is divisible by 5
• d5d6d7=357 is divisible by 7
• d6d7d8=572 is divisible by 11
• d7d8d9=728 is divisible by 13
• d8d9d10=289 is divisible by 17

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

We will take two different approaches to this. First We will explore the brute force of generating all permutations and after that we will use the divisibility requirements to limit the number of permutations we have to explore. Continue reading →

Posted by Kristian in Project Euler, 18 comments

## Project Euler 41: What is the largest n-digit pandigital prime that exists?

This time we mix two old topics together and form a new question. This time Project Euler has mixed pandigital numbers and primes and Problem 41 asks us to find the largest such number. The problem description reads

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?

I will start solving it by brute force and as we shall see the approach is possible but very inefficient, so after that I will show you how to speed the process up by using a small property of numbers that I was taught in 4th grade or so – And no, I am not particularly gifted, the trick is just really simple. Continue reading →

Posted by Kristian in Project Euler, 13 comments

## Project Euler 38: What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, … ?

Pandigital numbers were the topic of Problem 32 and here in Problem 38 of Project Euler we visit them again. The problem reads

Take the number 192 and multiply it by each of 1, 2, and 3:

192 x 1 = 192
192 x 2 = 384
192 x 3 = 576 By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)

The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).

What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, … , n) where n > 1?

As we shall see the problem is pretty easy to solve once we do a bit of analysis.Â  Doing the analysis will give us a really simple piece of code which needs to check only a few numbers. Continue reading →

Posted by Kristian in Project Euler, 17 comments

## Project Euler 32: Find the sum of all numbers that can be written as pandigital products

Problem 32 of Project Euler is about a special kind of number – Pandigital numbers. Something I haven’t heard about before, but they are very much used in commercials as phone and credit card numbers. The problem reads

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, the 5-digit number, 15234, is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39Â x 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

Posted by Kristian in Project Euler, 14 comments