Main image of article Coding Challenge: Prove Your Factorial Fluency
This is the first coding challenge in a regular series and runs through October. We're looking for you to write a computer program in C#, C++ or Java to solve a programming problem. If you win, you get not only bragging rights, but a genuine Dice T-Shirt, too (!). employment competitionTo enter, you must submit just source code, not executable binaries. That way if there's a problem with your code, we may be able to fix it and of course by compiling and running it on my PC, we can ensure that it's fair. It also avoids the issue of running potentially dangerous code on a PC. The deadline for this Coding Challenge is Oct. 31, 2013.

The Problem

Consider all the nine digit integers where each digit 1-9 occurs only once. The lowest of these numbers is 123456789, the next is 123456798 and the highest is 987654321. There are 362,880 such numbers if I have my maths correct. It's 9! (9 Factorial) i.e., 362,880 different numbers. If the numbers are ordered starting from the highest to the lowest, you have to write a program that returns the 100,000th in this sequence. So the first five are these:
1) 987654321 2) 987654312 3) 987654231 4) 987654213 5) 987654132
If you follow this sequence starting with 1 - 987654321 then 2 - 987654312, what number is the 100,000th in the sequence?

Fastest Correct Answer Wins

To make it more interesting, you should also write your code to run as fast as possible. Speed is the criteria for winning, so we're looking for the fastest correct answer. You should include timing code in your program and it should time with an accuracy of 1 microsecond. All three languages can time code: Follow these links for timing code in C++, C# and Java. The upper limit on execution time is 15 minutes. If it takes any longer then you need to rewrite it or start again. Any program that takes longer than 15 minutes on the contest PC will be disqualified. If your solution is so fast that it runs in under a tenth of a second, please loop it multiple times so the total elapsed time is around five seconds. Then divide the five seconds by the number of times around the loop to give the average time per solution. Eg if it runs 75 times in 5 seconds then it's taking 1/15th of a second, or approx 0.06666 seconds.

The Output

Your program should output two lines as shown below, the answer followed by the time to do one iteration. (The value below is not the correct answer!)
678123452 4 minutes, 32.678 seconds

Submitting Code and Compiling

Please submit your entry zipped up as an attachment to this email address and please don't include any executable binaries such as exes or dlls. The competition PC is an i7 950 with 4 cores doubled to 8 by hyper threading and 24 GB of ram. You are allowed to use multithreading/multitasking etc. For compiling C++ and C# I'll use Visual Studio 2012. Please include all the project and solution files such as .suo, etc., so I can open the solution and build it. Code built with earlier versions (VS 2003, VS 2005, VS 2008 and VS 2010) are all acceptable. If you use GCC/G++ please let me know and include your preferred command line to optimize it. I use MinGW to build that on my Windows PC. All programs are compiled in Release mode, so please specify any optimization flags for GCC/G++ or specify them in the solution. For Java, I have Java 7 installed on my PC. If you use any third party open source libraries that need to be installed, please let me know. Again, the prizes are glory and a t-shirt. At the end of the competition we'll publish the last version of each entry on SourceForge and highlight a winner. Be sure to include your name and website in the source code comments. By entering this contest you agree to allow Dice to publish your source code with credit to you as the copyright owner.

Submitting Newer Entries

It's acceptable to submit newer versions right up until the deadline. If you've sent in several, then the most recent will be used.

The Results

Will be posted here and on SourceForge. I may periodically update this during the month as new entries come in. Soon after the deadline, the final results will be posted. Updated October 3 to correct example error.