Thanks to visit codestin.com
Credit goes to github.com

Skip to content

andrewmccarthy/polydiv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polydivisible number calculator

Explanation

In base 10, using the non-zero digits (i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9) can you arrange the numbers so that

  • the first digit is divisible by one (not hard)
  • the first two digits taken as a number are divisible by two
  • the first three digits taken as a number are divisible by three

...

  • All nine digits are divisible by nine.

The single answer for base 10 is 381654729.

This quick script calculates the solutions for any base specified on the command-line. It requires numpy only because I'm too lazy to write my own version of numpy.base_repr.

Update — I've translated the Python into C (using the GNU Multiple Precision Arithmetic Library). The initial C version was 6 times faster than the very-unoptimised Python. Some simple optimisations made it about 49 times faster than Python.

Output

For each base, the output shows a list of numbers, first in the given base, and secondly in base ten. For bases higher than 36, the first value is not converted and replaced with an asterisk

Inspiration

I'd written a program to solve this about 25 or more years ago in PET Basic on the Commodore 64, but to solve it in bases other than ten was suggested by Matt Parker's recent book Things to Make and Do in the Fourth Dimension.

Solutions

Unless my script is broken, here's the output of ./polydiv.py {2..30} to save you wasting time.

Testing base 2...
1 1
Testing base 3...
Testing base 4...
123 27
321 57
Testing base 5...
Testing base 6...
14325 2285
54321 7465
Testing base 7...
Testing base 8...
3254167 874615
5234761 1391089
5674321 1538257
Testing base 9...
Testing base 10...
381654729 381654729
Testing base 11...
Testing base 12...
Testing base 13...
Testing base 14...
9C3A5476B812D 559922224824157
Testing base 15...
Testing base 16...
Testing base 17...
Testing base 18...
Testing base 19...
Testing base 20...
Testing base 21...
Testing base 22...
Testing base 23...
Testing base 24...
Testing base 25...
Testing base 26...
Testing base 27...
Testing base 28...
Testing base 29...
Testing base 30...

About

Search for polydivisible numbers in any base

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors