fn add(a:i32,b:i32) -> i32{
    return a + b;
}
fn addOne(a:i32) -> i32 {
    return a + 1;
}
fn generate(limit:i32) -> Vec<i32>{
    let mut arr:Vec<i32> = Vec::new();
    for x in 1..limit {
        arr.push(x);
    }
    return arr;
}
fn generate_with(limit:i32,generator_func:fn(i32) -> i32) -> Vec<i32> {
    let mut arr:Vec<i32> = Vec::new();
    for x in generate(limit) {
        arr.push(generator_func(x));
    }
    return arr;
}
fn main() {
    let mut count = 0;
    let mut i = 0;
    while i < 100 {

        count = count + i;
        i = i + 1;
    }
    println!("Count with while loop:{}",count);
    count = 0;
    for x in generate(100) {
        count = count + x;
    }
    println!("Count with array generation:{}",count);
    count = generate(100).iter().sum();
    println!("Count with generation:{}",count);
    count = generate_with(100,|x| x + 1).into_iter().sum();
    println!("Count with generation_with:{}",count);
    count = generate_with(100,addOne).into_iter().sum();
    println!("Count with generation_with and function as parameter:{}",count);
}
