Project Euler 24

Project Euler problem number #24 deals with permutations in lexicographical order. A non-brute force approach involves a mixed base number system based on factorials.

This problem is one of those that I solved using pen and paper after some research. I used the following Wikipedia pages:

Finally, you will need to remember that the Wikipedia articles both counts 0,1,2,… while the Euler problem counts 1,2,3,…. That is, adjust your offsets properly

Factorial Number System

The factorial number system is a mixed base representation of a number. I have created a small JavaScript converter that converts base-10 numbers into the corresponding factorial base number. It works with standard JavaScript integers and is therefore only able to convert numbers less than 231 = 2147483648. In order to represent numbers larger than 9 I extend the numbers with A, B, C… hex-style!

Base 10 number :

Converted numbers:

Base 10Factorial