IEV
This commit is contained in:
parent
acb5c8976e
commit
843838f626
@ -1,13 +1,7 @@
|
||||
mod solutions;
|
||||
mod utils;
|
||||
use clap::Parser;
|
||||
use utils::run_solution;
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, Debug)]
|
||||
enum Problem {
|
||||
REVP,
|
||||
PRTM,
|
||||
}
|
||||
use utils::{run_solution, Problem};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
|
25
rust/src/solutions/iev.rs
Normal file
25
rust/src/solutions/iev.rs
Normal file
@ -0,0 +1,25 @@
|
||||
pub fn iev(file_content: String) -> String {
|
||||
let prob: [f64; 6] = [1.0, 1.0, 1.0, 0.75, 0.5, 0.0];
|
||||
let mut result: f64 = file_content
|
||||
.trim()
|
||||
.split_whitespace()
|
||||
.zip(prob.iter())
|
||||
.map(|(a, b)| a.parse::<f64>().unwrap() * b)
|
||||
.sum();
|
||||
// the problem specifies that the assumption is that every couple has exactly 2 offspring,
|
||||
// thus, we multiply the result by 2 here.
|
||||
result *= 2.0;
|
||||
return result.to_string();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_iev() {
|
||||
let input_content = "1 0 0 1 0 1".to_string();
|
||||
let expected = "3.5";
|
||||
assert_eq!(iev(input_content), expected);
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
mod iev;
|
||||
mod prtm;
|
||||
mod revp;
|
||||
pub use iev::iev;
|
||||
pub use prtm::prtm;
|
||||
pub use revp::revp;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{solutions, Problem};
|
||||
use crate::solutions;
|
||||
use std::{fs, io};
|
||||
|
||||
pub const AMINO_ACID_MASS_TABLE: [(char, f64); 20] = [
|
||||
@ -29,12 +29,20 @@ pub struct FastaRecord {
|
||||
pub sequence: String,
|
||||
}
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, Debug)]
|
||||
pub enum Problem {
|
||||
REVP,
|
||||
PRTM,
|
||||
IEV,
|
||||
}
|
||||
|
||||
pub fn run_solution(problem: Problem, in_file: &String, out_file: &String) {
|
||||
// parse the input file into a string
|
||||
let solution: io::Result<String> = match fs::read_to_string(in_file) {
|
||||
Ok(content) => match problem {
|
||||
Problem::REVP => Ok(solutions::revp(content)),
|
||||
Problem::PRTM => Ok(solutions::prtm(content)),
|
||||
Problem::IEV => Ok(solutions::iev(content)),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user