aboutsummaryrefslogtreecommitdiff
path: root/2022/03/a.rs
diff options
context:
space:
mode:
Diffstat (limited to '2022/03/a.rs')
-rw-r--r--2022/03/a.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/2022/03/a.rs b/2022/03/a.rs
new file mode 100644
index 0000000..568546c
--- /dev/null
+++ b/2022/03/a.rs
@@ -0,0 +1,26 @@
1mod common;
2use common::*;
3
4fn get_rep_val(rucksack: &[u8]) -> i64 {
5 let mut seen = [false; 256];
6 let mid = rucksack.len()/2;
7 for i in 0..mid {
8 seen[rucksack[i] as usize] = true;
9 }
10 for i in mid..rucksack.len() {
11 if seen[rucksack[i] as usize] {
12 return value(rucksack[i] as char);
13 }
14 }
15 panic!("Could not find repeated char");
16}
17
18fn main() {
19 let mut sum = 0;
20 let mut line = String::new();
21 while std::io::stdin().read_line(&mut line).unwrap() > 0 {
22 sum += get_rep_val(line.as_bytes());
23 line.clear();
24 }
25 println!("{sum}");
26}

Generated with cgit - Back to sebastiano.tronto.net