mirror of
https://bitbucket.org/Mattrixwv/projecteulerrust.git
synced 2025-12-06 17:43:58 -05:00
Added solution to problem 24
This commit is contained in:
@@ -46,3 +46,4 @@ pub mod Problem20;
|
||||
pub mod Problem21;
|
||||
pub mod Problem22;
|
||||
pub mod Problem23;
|
||||
pub mod Problem24;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//ProjectEulerRust/src/Problems/Problems22.rs
|
||||
//ProjectEulerRust/src/Problems/Problems23.rs
|
||||
//Matthew Ellison
|
||||
// Created: 06-17-20
|
||||
//Modified: 06-17-20
|
||||
//What is the total of all the name scores in this file?
|
||||
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/RustClasses
|
||||
/*
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
@@ -26,7 +26,7 @@ extern crate myClasses;
|
||||
use crate::Problems::Answer::Answer;
|
||||
|
||||
pub fn getDescription() -> String{
|
||||
"What is the total of all the name scores in this file?".to_string()
|
||||
"Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers".to_string()
|
||||
}
|
||||
|
||||
pub fn solve() -> Answer{
|
||||
|
||||
54
src/Problems/Problem24.rs
Normal file
54
src/Problems/Problem24.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
//ProjectEulerRust/src/Problems/Problems24.rs
|
||||
//Matthew Ellison
|
||||
// Created: 06-17-20
|
||||
//Modified: 06-17-20
|
||||
//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/RustClasses
|
||||
/*
|
||||
Copyright (C) 2020 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/>.
|
||||
*/
|
||||
|
||||
|
||||
extern crate myClasses;
|
||||
use crate::Problems::Answer::Answer;
|
||||
|
||||
pub fn getDescription() -> String{
|
||||
"What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?".to_string()
|
||||
}
|
||||
|
||||
pub fn solve() -> Answer{
|
||||
let NEEDED_PERM = 1_000_000;
|
||||
//Setup the variables
|
||||
let nums = "0123456789".to_string(); //The string that you are trying to find the permutations of
|
||||
|
||||
//Start the timer
|
||||
let mut timer = myClasses::Stopwatch::Stopwatch::new();
|
||||
timer.start();
|
||||
|
||||
//Get all the permutations of the string
|
||||
let permutations = myClasses::Algorithms::getPermutations(nums);
|
||||
|
||||
//Stop the timer
|
||||
timer.stop();
|
||||
|
||||
//Return the results
|
||||
return Answer::new(format!("The 1 millionth permutation is {}", permutations[NEEDED_PERM - 1]), timer.getString());
|
||||
}
|
||||
|
||||
/* Results:
|
||||
The 1 millionth permutation is 2783915460
|
||||
It took 13.659 seconds to solve this problem
|
||||
*/
|
||||
11
src/main.rs
11
src/main.rs
@@ -33,9 +33,9 @@ mod Problems;
|
||||
#[derive(PartialEq)]
|
||||
enum Selections{EMPTY, SOLVE, DESCRIPTION, LIST, EXIT, SIZE}
|
||||
|
||||
static problemNumbers: [u32; 24] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
static problemNumbers: [u32; 25] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||
20, 21, 22, 23];
|
||||
20, 21, 22, 23, 24];
|
||||
|
||||
fn main(){
|
||||
let mut selection = Selections::EMPTY;
|
||||
@@ -224,6 +224,10 @@ fn solveProblem(problemNumber: u32){
|
||||
println!("{}", Problems::Problem23::getDescription());
|
||||
println!("{}", Problems::Problem23::solve());
|
||||
}
|
||||
else if(problemNumber == 24){
|
||||
println!("{}", Problems::Problem24::getDescription());
|
||||
println!("{}", Problems::Problem24::solve());
|
||||
}
|
||||
}
|
||||
fn descriptionMenu(){
|
||||
//Give some extra space to print the description
|
||||
@@ -318,6 +322,9 @@ fn printDescription(problemNumber: u32){
|
||||
else if(problemNumber == 23){
|
||||
println!("{}", Problems::Problem23::getDescription());
|
||||
}
|
||||
else if(problemNumber == 24){
|
||||
println!("{}", Problems::Problem24::getDescription());
|
||||
}
|
||||
}
|
||||
fn getProblemNumber() -> u32{
|
||||
println!("Enter a problem number: ");
|
||||
|
||||
Reference in New Issue
Block a user