30 lines
		
	
	
		
			960 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			960 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| #![feature(iter_array_chunks)]
 | |
| 
 | |
| use std::{
 | |
|     collections::{hash_map::RandomState, HashSet},
 | |
|     fs::File,
 | |
|     io::{BufRead, BufReader},
 | |
|     iter::FromIterator,
 | |
| };
 | |
| 
 | |
| fn main() -> () {
 | |
|     let input = File::open("input.txt").unwrap();
 | |
|     let buf = BufReader::new(input);
 | |
| 
 | |
|     let score: u32 = buf.lines().array_chunks::<3>().map(|lines| {
 | |
|         let intersection = lines.iter().map(|line| {
 | |
|             HashSet::<_, RandomState>::from_iter(line.as_ref().unwrap().chars())
 | |
|         }).reduce(|acc, set| acc.intersection(&set).cloned().collect()).unwrap();
 | |
|         assert!(intersection.len() == 1);
 | |
|         intersection.into_iter().map(|char| {
 | |
|             let score: u32 = match char {
 | |
|                 'A'..='Z' => char as u32 - 'A' as u32 + 27,
 | |
|                 'a'..='z' => char as u32 - 'a' as u32 + 1,
 | |
|                 _ => panic!("nigger, that's invalid")
 | |
|             };
 | |
|             score
 | |
|         }).sum::<u32>()
 | |
|     }).sum();
 | |
|     println!("{:?}", score);
 | |
| }
 |