Right answer !
This commit is contained in:
		
					parent
					
						
							
								f4d2d3bf24
							
						
					
				
			
			
				commit
				
					
						5661ba3f2f
					
				
			
		
					 2 changed files with 11 additions and 6 deletions
				
			
		|  | @ -16,6 +16,6 @@ fn main() { | ||||||
|     { |     { | ||||||
|         let file_path = "prob3_part1.txt"; |         let file_path = "prob3_part1.txt"; | ||||||
|         let max_part1 = prob3::solve_part1(file_path); |         let max_part1 = prob3::solve_part1(file_path); | ||||||
|         println!("{max_part1}"); |         println!("Solution for problem 3 part 1: {max_part1}"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ use std::collections::HashSet; | ||||||
| pub fn solve_part1(file_path: &str) -> i32 { | pub fn solve_part1(file_path: &str) -> i32 { | ||||||
|     let binding = |     let binding = | ||||||
|         std::fs::read_to_string(file_path).expect("Please provide a text file as an argument."); |         std::fs::read_to_string(file_path).expect("Please provide a text file as an argument."); | ||||||
|     let content = binding |     binding | ||||||
|         .lines() |         .lines() | ||||||
|         .collect::<Vec<&str>>() |         .collect::<Vec<&str>>() | ||||||
|         .iter() |         .iter() | ||||||
|  | @ -11,9 +11,14 @@ pub fn solve_part1(file_path: &str) -> i32 { | ||||||
|             let (first, last) = item.split_at(item.len() / 2); |             let (first, last) = item.split_at(item.len() / 2); | ||||||
|             let second = last.chars().collect::<HashSet<char>>(); |             let second = last.chars().collect::<HashSet<char>>(); | ||||||
|             let intersection = first.chars().collect::<HashSet<char>>(); |             let intersection = first.chars().collect::<HashSet<char>>(); | ||||||
|             *intersection.intersection(&second).next().unwrap() |             let character = *intersection.intersection(&second).next().unwrap() as i32; | ||||||
|         }) |             if character >= ('a' as i32) { | ||||||
|         .collect::<Vec<char>>(); |                 character - 96 | ||||||
| 
 |             } else { | ||||||
|     0 |                 character - 38 | ||||||
|  |             } | ||||||
|  |         }) | ||||||
|  |         .collect::<Vec<i32>>() | ||||||
|  |         .iter() | ||||||
|  |         .sum::<i32>() | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue