mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
56 lines
1.9 KiB
Java
56 lines
1.9 KiB
Java
//ProjectEuler/Java/Problem24.java
|
|
//Matthew Ellison
|
|
// Created: 03-24-19
|
|
//Modified: 03-28-19
|
|
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
|
/*
|
|
Copyright (C) 2019 Matthew Ellison
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
import mattrixwv.Stopwatch;
|
|
import mattrixwv.Algorithms;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class Problem24{
|
|
private static final Integer NEEDED_PERM = 1000000; //The number of the permutation that you need
|
|
public static void main(String[] args){
|
|
//Setup the variables
|
|
Stopwatch timer = new Stopwatch();
|
|
String nums = "0123456789"; //The string that you are trying to find the permutations of
|
|
|
|
//Start the timer
|
|
timer.start();
|
|
|
|
//Get all the permutations of the string
|
|
ArrayList<String> permutations = Algorithms.getPermutations(nums);
|
|
|
|
//Stop the timer
|
|
timer.stop();
|
|
|
|
//Print the results
|
|
System.out.printf("The 1 millionth permutation is %s\n", permutations.get(NEEDED_PERM - 1));
|
|
System.out.printf("It took %s to run this algorithm\n", timer.getStr());
|
|
}
|
|
}
|
|
|
|
/* Results
|
|
The 1 millionth permutation is 2783915460
|
|
It took 1.503 seconds to run this algorithm
|
|
*/
|