Pandigital Numbers

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




Problem Description

bullet Pandigital numbers contain all of the digits 0 through 9 exactly once.
bullet "Almost pandigital" numbers contain no zeros and the digits 1 through 9 exactly once.

As an introduction to pandigital numbers, write  a program that finds:

  1. The smallest pandigital number that is a perfect square.
  2. A number and it's square which together contain digits 1 through 9 exactly once (i.e. form an "almost pandigital" number.

Addendum March 30, 2008:  Solutions for three additional sample problems proposed by viewers have been added: 

  1.  Find a pandigital number in which each subset of the first N digits considered as an integer is exactly divisible by N.  (For example. the number cannot be 1234567890 because even though "1" is divisible by 1, "12" is divisible by 2, and "123" is divisible by 3, "1234" is not divisible by 4.)
  2. Find all equations of the form a x b = c with the property that a, b, and c are integers and collectively they form an almost pandigital number, i.e. they contain the digits 1 through 9 exactly once.
  3. Find all almost pandigital numbers, using digits 1 thru 9 only once each, with the property that its square contains each digit 1 thru 9 twice.

Addendum May 31, 2010:  Version 3.1 adds one more problem today.  This solves the problem posed by Listener Crossword #4088, "Digimix".  It seems that "Listener" crossword puzzles are published weekly in the London Times which charges for current puzzles (!) but are available for free after a few weeks at

  1. Find integers X and Y which together form an Almost pandigital number (X and Y together contain only the digits 1 through 9 exactly once) and the sum of whose squares(X2 + Y2) is also Almost pandigital.

Background & Techniques.

Both problems depend on generating pandigital numbers in increasing sequence.   Function GetNextPandigital performs this job for us.   It uses the Sawada/SEPA  permutation algorithm introduced in Permutes1.  

Some definitions of pandigital specify that it cannot begin with 0, others do not and I haven't found an "official" definition.  In solving the first problem, I added a checkbox that lets the user decide if leading zeros count.  Allowing a leading zero,  the smallest pandigital is 0123456789;  without a leading zero the smallest is 1023456789.

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

There are pairs of  pandigital numbers who's products are palindromes.   How many can you find?
If abcdefghi is an "almost pandigital" number, find the only value satisfying  a/bc + d/ef +g/hi = 1.

Original Date: August 25,2002 

Modified: May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.