using System.Collections.Generic;
using System.Diagnostics;
public static void Main(string[] args) {
new Problem24().BruteForce();
new Problem24().Factorial();
int[] perm = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
public void BruteForce() {
Stopwatch clock = Stopwatch.StartNew();
while (count < numPerm) {
while (perm[i - 1] >= perm[i]) {
while (perm[j - 1] <= perm[i - 1]) {
for (int k = 0; k < perm.Length; k++) {
permNum = permNum + perm[k];
Console.WriteLine("The millionth lexicographic permutation is: {0}", permNum);
Console.WriteLine("Solution took {0} ms", clock.ElapsedMilliseconds);
private void swap(int i, int j) {
public void Factorial() {
Stopwatch clock = Stopwatch.StartNew();
List<int> numbers = new List<int>();
for (int i = 0; i < N; i++) {
for (int i = 1; i < N; i++) {
int j = remain / Factor(N - i);
remain = remain % Factor(N - i);
permNum = permNum + numbers[j];
for (int i = 0; i < numbers.Count; i++) {
permNum = permNum + numbers[i];
Console.WriteLine("The millionth lexicographic permutation is: {0}", permNum);
Console.WriteLine("Solution took {0} ms", clock.ElapsedMilliseconds);
private int Factor(int i) {
for (int j = 1; j <= i; j++) {