This commit is contained in:
DavidOnTop 2025-04-10 14:31:27 +02:00
parent 27c33e1992
commit 5e7b7a2c01
Signed by: DavidOnTop
GPG key ID: 8D3E9A75E3E13D89
20 changed files with 298 additions and 219 deletions

View file

@ -11,5 +11,8 @@ pub fn main() {
println!("zadajte cislo");
std::io::stdin().read_line(&mut input).unwrap();
let input: f32 = input.trim().parse().unwrap();
println!("{}", v.iter().position(|x| *x == input).unwrap_or(usize::MAX))
println!(
"{}",
v.iter().position(|x| *x == input).unwrap_or(usize::MAX)
)
}

View file

@ -8,6 +8,16 @@ pub fn main() {
panic!("Invalid input");
}
let mut input = input.to_lowercase();
input = input.chars().enumerate().map(|(i, c)| if i == 0 { c.to_uppercase().next().unwrap() } else { c }).collect();
input = input
.chars()
.enumerate()
.map(|(i, c)| {
if i == 0 {
c.to_uppercase().next().unwrap()
} else {
c
}
})
.collect();
println!("{}", input);
}

View file

@ -4,14 +4,15 @@ pub fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
match input.trim() {
"1." | "1" | "mtokm" => read_and_convert(|u| {u * 1.609344}),
"2." | "2" | "kmtom" => read_and_convert(|u| {u / 1.609344}),
"1." | "1" | "mtokm" => read_and_convert(|u| u * 1.609344),
"2." | "2" | "kmtom" => read_and_convert(|u| u / 1.609344),
_ => {}
}
}
fn read_and_convert<F>(tom: F)
where F: Fn(f64) -> f64
where
F: Fn(f64) -> f64,
{
println!("zadaj udaj");
let mut input = String::new();

View file

@ -7,8 +7,17 @@ pub fn main() {
teploty.push(rand.gen::<f64>() * 40.0 - 20.0);
}
println!("teploty: {:?}", teploty);
println!("najnizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::min).unwrap());
println!("najvizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::max).unwrap());
println!(
"najnizsia {}",
teploty.iter().map(|e| e.clone()).reduce(f64::min).unwrap()
);
println!(
"najvizsia {}",
teploty.iter().map(|e| e.clone()).reduce(f64::max).unwrap()
);
println!("priemer {}", teploty.iter().sum::<f64>() / 20.0);
println!("pocet nulovych teplot: {}", teploty.iter().find(|e| **e == 0.0).iter().count())
println!(
"pocet nulovych teplot: {}",
teploty.iter().find(|e| **e == 0.0).iter().count()
)
}

View file

@ -2,9 +2,15 @@ static DNA: &'static str = "AACTATTTCGGGGGGCGAGCCCTCATCGTCTCTTCTGCGGATGACTCAACAC
static DNAMUT: &'static str = "AACTATGTCGCGAGGCGAGCTCTCATCGTCTCGTCTGCGGATGACTCCACACGCTAGCGACGTGAAGTCGAATCCGTCGATGGTTATAAATCAGAGACTCAGAGTGCTGTCTGGAGCGTGAATCTAACGGTACGTATCTCGATAGCTCGGTCGCTTTTCGCACTCCGCGAAAGTTCGTACCGCTCATACACTAGGTTGCGAAGCCTATGCTGATATATGAATCCACACTAGAGCAGTGCTCTTAAGAATCGCAGTTGTAAATACTTAATACTCCAATCGGCTTTTACGTGCACCACCGCGCGCGGCTGACAAGGGTCTCACATCGGGAAACAAGACAGTTCCGGGCTGGAAGTAGCGCCGGCTAAGGAAGACGCCTGGTACGGCAGGACTATGAAACCAGTACAAAGGCAACATCCTCACTTGGGTGAACGGAAACGCAGTATTATGGTTACTTCCTGGATACGTGAAACATATCCCATGGTAGTCCTTAGACTTGGGAGTCTATCACCCCTAGGGCCCATATCTGGAGATAGACGCCAGGTTGAATCCGTATTTGGAGGTACGATGGAACAGTCTGGGTGGGACGTGCTTCATTTATACCCTGCGCAGGCTGGACCGAGGACCGCAAGGTGCGGCGGTGCACAAGCAATTGACAACTAACCACCGTGTATTCATTATGGTACCAGGAACTTTAAGCCGAGTCAATGAAGCTCGCATTACAGTGTGTACCGCATCTTGCCGTTACTCACACACTGTGATCCACCACAAGTCAAGCCATTGCCTCTCTGACACGCCGTAAGAATTAATATGTAAACTTTGCGCGGGTTGACTGCGATCCGTTCAGTCTCGTCCGAGGGCACAATCCTATTCCCATTTGTATGTTCAGCTAACTTCTACCCATCCTCTGAAGTTAAGTAGGTCGTGAGATGCCATGGAGGCTCTCGTTCATCCCGTGGGACATCAAGCTTCCCCTTGATAAAGCACCCCGCTCGGGTGTAAA";
pub fn main() {
DNA.chars().zip(DNAMUT.chars()).enumerate().for_each(|(i, (d, m))| {
DNA.chars()
.zip(DNAMUT.chars())
.enumerate()
.for_each(|(i, (d, m))| {
if (d != m) {
println!("Mutacia nastala na {} pozicii povodna {d}, nova {m}", i + 1)
println!(
"Mutacia nastala na {} pozicii povodna {d}, nova {m}",
i + 1
)
}
})
}

View file

@ -10,7 +10,7 @@ pub fn main() {
println!("{}F", num * 1.8 + 32.0)
}
'F' | 'f' => {
println!("{}C", (num - 32.0)/1.8)
println!("{}C", (num - 32.0) / 1.8)
}
_ => {
println!("nepodporovana znacka")

View file

@ -28,17 +28,16 @@ impl Display for LengthError {
impl Error for LengthError {}
fn pocet_chyb(i1: String, i2: String) -> Result<usize, LengthError> {
if i1.len() != i2.len() {
return Err(LengthError("Dna a complementarne dna niesu rovnako dlhe".to_string()))
return Err(LengthError(
"Dna a complementarne dna niesu rovnako dlhe".to_string(),
));
}
let mut n: usize = 0;
i1.chars().zip(i2.chars()).for_each(|cp| {
match cp {
i1.chars().zip(i2.chars()).for_each(|cp| match cp {
('A', 'T') | ('T', 'A') | ('C', 'G') | ('G', 'C') => (),
_ => n += 1
}
_ => n += 1,
});
Ok(n)
}
@ -49,13 +48,13 @@ fn percento_chyb(i1: String, i2: String) -> f64 {
}
fn generuj_retazec(i1: String) -> String {
i1.chars().map(|c| {
match c {
i1.chars()
.map(|c| match c {
'A' => 'T',
'T' => 'A',
'C' => 'G',
'G' => 'C',
_ => ' ',
}
}).collect()
})
.collect()
}

View file

@ -2,7 +2,12 @@ use std::fs::OpenOptions;
use std::io::Write;
pub fn main() {
let mut file = OpenOptions::new().create(true).truncate(true).write(true).open("./cisla.txt").unwrap();
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("./cisla.txt")
.unwrap();
let mut cisla = Vec::with_capacity(21);
for i in 0..20 {
let mut input = String::new();
@ -14,5 +19,13 @@ pub fn main() {
let avg = cisla.iter().sum::<f64>() / 20f64;
println!("priemer: {avg}");
cisla.push(avg);
file.write_all(cisla.iter().map(|f| f.to_string()).collect::<Vec<String>>().join("\n").as_bytes()).unwrap()
file.write_all(
cisla
.iter()
.map(|f| f.to_string())
.collect::<Vec<String>>()
.join("\n")
.as_bytes(),
)
.unwrap()
}

View file

@ -8,7 +8,12 @@ pub fn main() {
let input = input.trim().to_string();
let povodny_pocet = input.clone().chars().filter(|c| *c == '_').count();
let diktat = input.replace(['i', 'í', 'y', 'ý'], "_");
let mut file = OpenOptions::new().create(true).truncate(true).write(true).open("./doplnovacka.txt").unwrap();
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("./doplnovacka.txt")
.unwrap();
file.write_all(diktat.clone().as_bytes()).unwrap();
let max = diktat.chars().filter(|c| *c == '_').count() - povodny_pocet;
println!("Max pocet chyb: {}", max);

View file

@ -25,4 +25,3 @@ pub fn max(i1: i32, i2: i32) -> Option<i32> {
Some(i2)
}
}

View file

@ -1,6 +1,6 @@
pub fn main() {
let mut sutaziaci = vec![("aoeu", 21), ("htns", 25), ("pyfg", 16)];
sutaziaci.sort_by(|s, l| {s.1.cmp(&l.1)});
sutaziaci.sort_by(|s, l| s.1.cmp(&l.1));
sutaziaci.iter().for_each(|n| {
println!("{} {}", n.0, n.1);
})

View file

@ -15,11 +15,13 @@ pub fn main() {
let num1: f64 = num1.trim().parse().unwrap();
let operator = match operand.as_str() {
"+" => {|c1: f64, c2: f64| {c1 + c2}}
"-" => {|c1: f64, c2: f64| {c1 - c2}}
"*" => {|c1: f64, c2: f64| {c1 * c2}}
"/" => {|c1: f64, c2: f64| {c1 / c2}}
_ => {panic!("Zly operator")}
"+" => |c1: f64, c2: f64| c1 + c2,
"-" => |c1: f64, c2: f64| c1 - c2,
"*" => |c1: f64, c2: f64| c1 * c2,
"/" => |c1: f64, c2: f64| c1 / c2,
_ => {
panic!("Zly operator")
}
};
let result = operator(num, num1);

View file

@ -9,8 +9,24 @@ pub fn main() {
println!("Zadaj ziaka {i}, vo formate: meno priezvisko, trieda, znamka znamka znamka znamka znamka");
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let input = input.trim().split(",").map(|s| {s.trim().to_string()}).collect::<Vec<_>>();
ziaci.push((input[0].clone(), input[1].clone(), input[2].clone().split(" ").map(|z| {z.parse::<i32>().unwrap()}).collect::<Vec<_>>()));
let input = input
.trim()
.split(",")
.map(|s| s.trim().to_string())
.collect::<Vec<_>>();
ziaci.push((
input[0].clone(),
input[1].clone(),
input[2]
.clone()
.split(" ")
.map(|z| z.parse::<i32>().unwrap())
.collect::<Vec<_>>(),
));
}
let ziaci = ziaci.iter().map(|z| (z, z.2.iter().sum::<i32>() as f64 / 5.0)).collect::<Vec<_>>().sort_by(|z, e| {z.1.partial_cmp(&e.1)});
let ziaci = ziaci
.iter()
.map(|z| (z, z.2.iter().sum::<i32>() as f64 / 5.0))
.collect::<Vec<_>>()
.sort_by(|z, e| z.1.partial_cmp(&e.1).unwrap());
}

View file

@ -3,7 +3,9 @@ pub fn main() {
}
fn rec(num: i32) {
if num >= 1000 {return;}
if num >= 1000 {
return;
}
println!("num: {num}");
rec(num + 7)
}

View file

@ -1,20 +1,34 @@
pub fn main() {
let ziaci = ["Horák Marek","Gajdáč Tibor","Velická Barbora","Malík Peter","Malíková Diana"];
let ziaci = [
"Horák Marek",
"Gajdáč Tibor",
"Velická Barbora",
"Malík Peter",
"Malíková Diana",
];
let hodiny= [15,0,0,75,34];
let hodiny = [15, 0, 0, 75, 34];
println!("Vsetky vymeskane hodiniy: {}", hodiny.iter().sum::<i32>());
println!("Priemerny pocet vymeskanych hodin: {}", hodiny.iter().sum::<i32>() as f64 / hodiny.len() as f64);
let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| {z.1.cmp(&e.1)});
println!(
"Priemerny pocet vymeskanych hodin: {}",
hodiny.iter().sum::<i32>() as f64 / hodiny.len() as f64
);
let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| z.1.cmp(&e.1));
if let Some(najhorsi) = najhorsi {
println!("Najhorsiu dochadzku ma: {} s dochadzkou {}", najhorsi.0, najhorsi.1)
println!(
"Najhorsiu dochadzku ma: {} s dochadzkou {}",
najhorsi.0, najhorsi.1
)
} else {
println!("Nepodarilo sa najst najhorsieho")
}
let s0 = ziaci.iter().zip(hodiny).filter(|e| {e.1 == 0}).collect::<Vec<_>>();
let s0 = ziaci
.iter()
.zip(hodiny)
.filter(|e| e.1 == 0)
.collect::<Vec<_>>();
println!("pocet ziakou ktori mozu mat pochvalu: {}", s0.len());
println!("Ziaci na pochvalu");
s0.iter().for_each(|e| {
println!(" {}", e.0)
});
s0.iter().for_each(|e| println!(" {}", e.0));
}