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"); println!("zadajte cislo");
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let input: f32 = input.trim().parse().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"); panic!("Invalid input");
} }
let mut input = input.to_lowercase(); 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); println!("{}", input);
} }

View file

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

View file

@ -7,8 +7,17 @@ pub fn main() {
teploty.push(rand.gen::<f64>() * 40.0 - 20.0); teploty.push(rand.gen::<f64>() * 40.0 - 20.0);
} }
println!("teploty: {:?}", teploty); println!("teploty: {:?}", teploty);
println!("najnizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::min).unwrap()); println!(
println!("najvizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::max).unwrap()); "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!("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"; static DNAMUT: &'static str = "AACTATGTCGCGAGGCGAGCTCTCATCGTCTCGTCTGCGGATGACTCCACACGCTAGCGACGTGAAGTCGAATCCGTCGATGGTTATAAATCAGAGACTCAGAGTGCTGTCTGGAGCGTGAATCTAACGGTACGTATCTCGATAGCTCGGTCGCTTTTCGCACTCCGCGAAAGTTCGTACCGCTCATACACTAGGTTGCGAAGCCTATGCTGATATATGAATCCACACTAGAGCAGTGCTCTTAAGAATCGCAGTTGTAAATACTTAATACTCCAATCGGCTTTTACGTGCACCACCGCGCGCGGCTGACAAGGGTCTCACATCGGGAAACAAGACAGTTCCGGGCTGGAAGTAGCGCCGGCTAAGGAAGACGCCTGGTACGGCAGGACTATGAAACCAGTACAAAGGCAACATCCTCACTTGGGTGAACGGAAACGCAGTATTATGGTTACTTCCTGGATACGTGAAACATATCCCATGGTAGTCCTTAGACTTGGGAGTCTATCACCCCTAGGGCCCATATCTGGAGATAGACGCCAGGTTGAATCCGTATTTGGAGGTACGATGGAACAGTCTGGGTGGGACGTGCTTCATTTATACCCTGCGCAGGCTGGACCGAGGACCGCAAGGTGCGGCGGTGCACAAGCAATTGACAACTAACCACCGTGTATTCATTATGGTACCAGGAACTTTAAGCCGAGTCAATGAAGCTCGCATTACAGTGTGTACCGCATCTTGCCGTTACTCACACACTGTGATCCACCACAAGTCAAGCCATTGCCTCTCTGACACGCCGTAAGAATTAATATGTAAACTTTGCGCGGGTTGACTGCGATCCGTTCAGTCTCGTCCGAGGGCACAATCCTATTCCCATTTGTATGTTCAGCTAACTTCTACCCATCCTCTGAAGTTAAGTAGGTCGTGAGATGCCATGGAGGCTCTCGTTCATCCCGTGGGACATCAAGCTTCCCCTTGATAAAGCACCCCGCTCGGGTGTAAA";
pub fn main() { pub fn main() {
DNA.chars().zip(DNAMUT.chars()).enumerate().for_each(|(i, (d, m))| { DNA.chars()
if (d != m) { .zip(DNAMUT.chars())
println!("Mutacia nastala na {} pozicii povodna {d}, nova {m}", i + 1) .enumerate()
} .for_each(|(i, (d, m))| {
}) if (d != m) {
println!(
"Mutacia nastala na {} pozicii povodna {d}, nova {m}",
i + 1
)
}
})
} }

View file

@ -1,7 +1,7 @@
pub fn main() { pub fn main() {
for i in 1..5 { for i in 1..5 {
for j in 0..10 { for j in 0..10 {
println!("{i}{j}{i}") println!("{i}{j}{i}")
} }
} }
} }

View file

@ -1,19 +1,19 @@
pub fn main() { pub fn main() {
println!("Zadaj cislo a znacku (F/C)"); println!("Zadaj cislo a znacku (F/C)");
let mut input = String::new(); let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let mut input = input.trim().to_string(); let mut input = input.trim().to_string();
let unit = input.remove(input.len() - 1); let unit = input.remove(input.len() - 1);
let num: f64 = input.parse().expect("Neda sa retazec premenit na cislo"); let num: f64 = input.parse().expect("Neda sa retazec premenit na cislo");
match unit { match unit {
'C' | 'c' => { 'C' | 'c' => {
println!("{}F", num * 1.8 + 32.0) println!("{}F", num * 1.8 + 32.0)
} }
'F' | 'f' => { 'F' | 'f' => {
println!("{}C", (num - 32.0)/1.8) println!("{}C", (num - 32.0) / 1.8)
} }
_ => { _ => {
println!("nepodporovana znacka") println!("nepodporovana znacka")
} }
} }
} }

View file

@ -1,15 +1,15 @@
static SAM: &str = "aeiyou"; static SAM: &str = "aeiyou";
pub fn main() { pub fn main() {
let mut input = String::new(); let mut input = String::new();
println!("Zadaj slovo"); println!("Zadaj slovo");
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let mut input = input.trim().to_string(); let mut input = input.trim().to_string();
if SAM.contains(input.chars().next().expect("Slovo musi mat aspon 1 znak")) { if SAM.contains(input.chars().next().expect("Slovo musi mat aspon 1 znak")) {
println!("{input}way") println!("{input}way")
} else { } else {
let c = input.chars().next().unwrap(); let c = input.chars().next().unwrap();
input.replace_range(0..1, ""); input.replace_range(0..1, "");
println!("{input}{c}ay") println!("{input}{c}ay")
} }
} }

View file

@ -1,14 +1,14 @@
static SAM: &str = "aeiyouáéíóúý"; static SAM: &str = "aeiyouáéíóúý";
pub fn main() { pub fn main() {
let mut input = String::new(); let mut input = String::new();
println!("Zadaj vetu"); println!("Zadaj vetu");
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let mut input = input.trim().to_string(); let mut input = input.trim().to_string();
for c in SAM.chars() { for c in SAM.chars() {
input = input.replace(c, "_"); input = input.replace(c, "_");
} }
println!("{input}"); println!("{input}");
} }

View file

@ -2,60 +2,59 @@ use std::error::Error;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
pub fn main() { pub fn main() {
let mut input1 = String::new(); let mut input1 = String::new();
println!("Zadaj 1 retazec DNA"); println!("Zadaj 1 retazec DNA");
std::io::stdin().read_line(&mut input1).unwrap(); std::io::stdin().read_line(&mut input1).unwrap();
let input1 = input1.trim().to_uppercase().to_string(); let input1 = input1.trim().to_uppercase().to_string();
let mut input2 = String::new(); let mut input2 = String::new();
println!("Zadaj 2 complementarny retazec DNA"); println!("Zadaj 2 complementarny retazec DNA");
std::io::stdin().read_line(&mut input2).unwrap(); std::io::stdin().read_line(&mut input2).unwrap();
let input2 = input2.trim().to_uppercase().to_string(); let input2 = input2.trim().to_uppercase().to_string();
let n_chyb = pocet_chyb(input1.clone(), input2.clone()).unwrap(); let n_chyb = pocet_chyb(input1.clone(), input2.clone()).unwrap();
println!("Pocet chyb: {n_chyb}"); println!("Pocet chyb: {n_chyb}");
println!("Percento chyb: {}", percento_chyb(input1.clone(), input2)); println!("Percento chyb: {}", percento_chyb(input1.clone(), input2));
println!("Complementarny retazec: {}", generuj_retazec(input1)); println!("Complementarny retazec: {}", generuj_retazec(input1));
} }
#[derive(Default, Debug)] #[derive(Default, Debug)]
struct LengthError(String); struct LengthError(String);
impl Display for LengthError { impl Display for LengthError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f) std::fmt::Display::fmt(&self.0, f)
} }
} }
impl Error for LengthError {} impl Error for LengthError {}
fn pocet_chyb(i1: String, i2: String) -> Result<usize, LengthError> { fn pocet_chyb(i1: String, i2: String) -> Result<usize, LengthError> {
if i1.len() != i2.len() { 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 { let mut n: usize = 0;
('A', 'T') | ('T', 'A') | ('C', 'G') | ('G', 'C') => (), i1.chars().zip(i2.chars()).for_each(|cp| match cp {
_ => n += 1 ('A', 'T') | ('T', 'A') | ('C', 'G') | ('G', 'C') => (),
} _ => n += 1,
}); });
Ok(n) Ok(n)
} }
fn percento_chyb(i1: String, i2: String) -> f64 { fn percento_chyb(i1: String, i2: String) -> f64 {
let n_chyb = pocet_chyb(i1.clone(), i2).unwrap(); let n_chyb = pocet_chyb(i1.clone(), i2).unwrap();
(n_chyb as f64 / i1.len() as f64) * 100f64 (n_chyb as f64 / i1.len() as f64) * 100f64
} }
fn generuj_retazec(i1: String) -> String { fn generuj_retazec(i1: String) -> String {
i1.chars().map(|c| { i1.chars()
match c { .map(|c| match c {
'A' => 'T', 'A' => 'T',
'T' => 'A', 'T' => 'A',
'C' => 'G', 'C' => 'G',
'G' => 'C', 'G' => 'C',
_ => ' ', _ => ' ',
} })
}).collect() .collect()
} }

View file

@ -2,17 +2,30 @@ use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
pub fn main() { pub fn main() {
let mut file = OpenOptions::new().create(true).truncate(true).write(true).open("./cisla.txt").unwrap(); let mut file = OpenOptions::new()
let mut cisla = Vec::with_capacity(21); .create(true)
for i in 0..20 { .truncate(true)
let mut input = String::new(); .write(true)
println!("Zadaj cislo {} z 20", i + 1); .open("./cisla.txt")
std::io::stdin().read_line(&mut input).unwrap(); .unwrap();
let inp: f64 = input.trim().parse().unwrap(); let mut cisla = Vec::with_capacity(21);
cisla.push(inp); for i in 0..20 {
} let mut input = String::new();
let avg = cisla.iter().sum::<f64>() / 20f64; println!("Zadaj cislo {} z 20", i + 1);
println!("priemer: {avg}"); std::io::stdin().read_line(&mut input).unwrap();
cisla.push(avg); let inp: f64 = input.trim().parse().unwrap();
file.write_all(cisla.iter().map(|f| f.to_string()).collect::<Vec<String>>().join("\n").as_bytes()).unwrap() cisla.push(inp);
}
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()
} }

View file

@ -2,14 +2,19 @@ use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
pub fn main() { pub fn main() {
let mut input = String::new(); let mut input = String::new();
println!("Zadaj diktat"); println!("Zadaj diktat");
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let input = input.trim().to_string(); let input = input.trim().to_string();
let povodny_pocet = input.clone().chars().filter(|c| *c == '_').count(); let povodny_pocet = input.clone().chars().filter(|c| *c == '_').count();
let diktat = input.replace(['i', 'í', 'y', 'ý'], "_"); 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()
file.write_all(diktat.clone().as_bytes()).unwrap(); .create(true)
let max = diktat.chars().filter(|c| *c == '_').count() - povodny_pocet; .truncate(true)
println!("Max pocet chyb: {}", max); .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

@ -1,28 +1,27 @@
pub fn main() { pub fn main() {
let mut input1 = String::new(); let mut input1 = String::new();
std::io::stdin().read_line(&mut input1).unwrap(); std::io::stdin().read_line(&mut input1).unwrap();
let input1 = input1.trim().parse().unwrap(); let input1 = input1.trim().parse().unwrap();
let mut input2 = String::new(); let mut input2 = String::new();
std::io::stdin().read_line(&mut input2).unwrap(); std::io::stdin().read_line(&mut input2).unwrap();
let input2 = input2.trim().parse().unwrap(); let input2 = input2.trim().parse().unwrap();
let res = max(input1, input2); let res = max(input1, input2);
if let Some(res) = res { if let Some(res) = res {
println!("{res}") println!("{res}")
} else { } else {
println!("rovnake") println!("rovnake")
} }
} }
pub fn max(i1: i32, i2: i32) -> Option<i32> { pub fn max(i1: i32, i2: i32) -> Option<i32> {
let res = (i1.to_string().len(), i2.to_string().len()); let res = (i1.to_string().len(), i2.to_string().len());
if res.0 == res.1 { if res.0 == res.1 {
None None
} else if res.0 > res.1 { } else if res.0 > res.1 {
Some(i1) Some(i1)
} else { } else {
Some(i2) Some(i2)
} }
} }

View file

@ -1,7 +1,7 @@
pub fn main() { pub fn main() {
let mut sutaziaci = vec![("aoeu", 21), ("htns", 25), ("pyfg", 16)]; 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| { sutaziaci.iter().for_each(|n| {
println!("{} {}", n.0, n.1); println!("{} {}", n.0, n.1);
}) })
} }

View file

@ -1,27 +1,29 @@
pub fn main() { pub fn main() {
println!("Prve cislo: "); println!("Prve cislo: ");
let mut num = String::new(); let mut num = String::new();
std::io::stdin().read_line(&mut num).unwrap(); std::io::stdin().read_line(&mut num).unwrap();
let num: f64 = num.trim().parse().unwrap(); let num: f64 = num.trim().parse().unwrap();
println!("operator: "); println!("operator: ");
let mut operand = String::new(); let mut operand = String::new();
std::io::stdin().read_line(&mut operand).unwrap(); std::io::stdin().read_line(&mut operand).unwrap();
let operand = operand.trim().to_string(); let operand = operand.trim().to_string();
println!("Druhe cislo: "); println!("Druhe cislo: ");
let mut num1 = String::new(); let mut num1 = String::new();
std::io::stdin().read_line(&mut num1).unwrap(); std::io::stdin().read_line(&mut num1).unwrap();
let num1: f64 = num1.trim().parse().unwrap(); let num1: f64 = num1.trim().parse().unwrap();
let operator = match operand.as_str() { 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,
"*" => {|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")} _ => {
}; panic!("Zly operator")
}
};
let result = operator(num, num1); let result = operator(num, num1);
println!("Vysledok {result}"); println!("Vysledok {result}");
} }

View file

@ -1,13 +1,13 @@
pub fn main() { pub fn main() {
println!("Zaklad"); println!("Zaklad");
let mut inp = String::new(); let mut inp = String::new();
std::io::stdin().read_line(&mut inp).unwrap(); std::io::stdin().read_line(&mut inp).unwrap();
let inp: f64 = inp.trim().parse().unwrap(); let inp: f64 = inp.trim().parse().unwrap();
println!("mocnitel: "); println!("mocnitel: ");
let mut n = String::new(); let mut n = String::new();
std::io::stdin().read_line(&mut n).unwrap(); std::io::stdin().read_line(&mut n).unwrap();
let n: f64 = n.trim().parse().unwrap(); let n: f64 = n.trim().parse().unwrap();
println!("vysledok: {}", inp.powf(n)) println!("vysledok: {}", inp.powf(n))
} }

View file

@ -1,16 +1,32 @@
pub fn main() { pub fn main() {
println!("pocet ziakov: "); println!("pocet ziakov: ");
let mut num = String::new(); let mut num = String::new();
std::io::stdin().read_line(&mut num).unwrap(); std::io::stdin().read_line(&mut num).unwrap();
let num: usize = num.trim().parse().unwrap(); let num: usize = num.trim().parse().unwrap();
let mut ziaci = Vec::with_capacity(num); let mut ziaci = Vec::with_capacity(num);
for i in 0..num { for i in 0..num {
println!("Zadaj ziaka {i}, vo formate: meno priezvisko, trieda, znamka znamka znamka znamka znamka"); println!("Zadaj ziaka {i}, vo formate: meno priezvisko, trieda, znamka znamka znamka znamka znamka");
let mut input = String::new(); let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap(); std::io::stdin().read_line(&mut input).unwrap();
let input = input.trim().split(",").map(|s| {s.trim().to_string()}).collect::<Vec<_>>(); let input = input
ziaci.push((input[0].clone(), input[1].clone(), input[2].clone().split(" ").map(|z| {z.parse::<i32>().unwrap()}).collect::<Vec<_>>())); .trim()
} .split(",")
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)}); .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).unwrap());
} }

View file

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

View file

@ -1,20 +1,34 @@
pub fn main() { 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!("Vsetky vymeskane hodiniy: {}", hodiny.iter().sum::<i32>());
println!("Priemerny pocet vymeskanych hodin: {}", hodiny.iter().sum::<i32>() as f64 / hodiny.len() as f64); println!(
let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| {z.1.cmp(&e.1)}); "Priemerny pocet vymeskanych hodin: {}",
if let Some(najhorsi) = najhorsi { hodiny.iter().sum::<i32>() as f64 / hodiny.len() as f64
println!("Najhorsiu dochadzku ma: {} s dochadzkou {}", najhorsi.0, najhorsi.1) );
} else { let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| z.1.cmp(&e.1));
println!("Nepodarilo sa najst najhorsieho") if let Some(najhorsi) = najhorsi {
} println!(
let s0 = ziaci.iter().zip(hodiny).filter(|e| {e.1 == 0}).collect::<Vec<_>>(); "Najhorsiu dochadzku ma: {} s dochadzkou {}",
println!("pocet ziakou ktori mozu mat pochvalu: {}", s0.len()); najhorsi.0, najhorsi.1
println!("Ziaci na pochvalu"); )
s0.iter().for_each(|e| { } else {
println!(" {}", e.0) println!("Nepodarilo sa najst najhorsieho")
}); }
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));
} }