aboutsummaryrefslogtreecommitdiff
path: root/challenge-338/benjamin-andre/rust/ch-1.rs
blob: 798b6315435874e2b01dc90954398b8439d3520f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit

fn highest_row(matrix: &[&[i32]]) -> i32 {
    matrix.iter().map(|row| row.iter().sum()).max().unwrap()
}

#[test]
fn example() {
    assert_eq!(
        highest_row(&[&[4, 4, 4, 4], &[10, 0, 0, 0], &[2, 2, 2, 9]]),
        16
    );
    assert_eq!(highest_row(&[&[1, 5], &[7, 3], &[3, 5]]), 10);
    assert_eq!(highest_row(&[&[1, 2, 3], &[3, 2, 1]]), 6);
    assert_eq!(highest_row(&[&[2, 8, 7], &[7, 1, 3], &[1, 9, 5]]), 17);
    assert_eq!(
        highest_row(&[&[10, 20, 30], &[5, 5, 5], &[0, 100, 0], &[25, 25, 25]]),
        100
    );
}