d1p2
This commit is contained in:
		| @@ -2253,3 +2253,4 @@ | |||||||
| 1791 | 1791 | ||||||
| 1510 | 1510 | ||||||
| 5279 | 5279 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,18 +8,25 @@ fn main() { | |||||||
|     let input = &args[1]; |     let input = &args[1]; | ||||||
|     let reader = BufReader::new(File::open(input).expect("where file?")); |     let reader = BufReader::new(File::open(input).expect("where file?")); | ||||||
|  |  | ||||||
|     let mut sum: i64 = 0; |     let (mut sum, mut max1, mut max2, mut max3) = (0, 0, 0, 0); | ||||||
|     let mut max: i64 = 0; |  | ||||||
|     for line in reader.lines() { |     for line in reader.lines() { | ||||||
|         if !line.as_ref().unwrap().trim().is_empty() { |         if !line.as_ref().unwrap().trim().is_empty() { | ||||||
|             sum += line.unwrap().parse::<i64>().unwrap(); |             sum += line.unwrap().parse::<i64>().unwrap(); | ||||||
|         } else { |         } else { | ||||||
|             if sum > max { |             println!("  {}? {} {} {}", sum, max1, max2, max3); | ||||||
|                 max = sum; |             if sum > max1 { | ||||||
|  |                 max3 = max2; | ||||||
|  |                 max2 = max1; | ||||||
|  |                 max1 = sum; | ||||||
|  |             } else if sum > max2 { | ||||||
|  |                 max3 = max2; | ||||||
|  |                 max2 = sum; | ||||||
|  |             } else if sum > max3 { | ||||||
|  |                 max3 = sum; | ||||||
|             } |             } | ||||||
|             sum = 0; |             sum = 0; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     println!("Max: {}", max); |     println!("Max3: {}", max1 + max2 + max3); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								day1/src/main1.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								day1/src/main1.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | use std::env; | ||||||
|  | use std::fs::File; | ||||||
|  | use std::io::BufReader; | ||||||
|  | use std::io::BufRead; | ||||||
|  |  | ||||||
|  | fn main() { | ||||||
|  |     let args: Vec<String> = env::args().collect(); | ||||||
|  |     let input = &args[1]; | ||||||
|  |     let reader = BufReader::new(File::open(input).expect("where file?")); | ||||||
|  |  | ||||||
|  |     let mut sum: i64 = 0; | ||||||
|  |     let mut max: i64 = 0; | ||||||
|  |     for line in reader.lines() { | ||||||
|  |         if !line.as_ref().unwrap().trim().is_empty() { | ||||||
|  |             sum += line.unwrap().parse::<i64>().unwrap(); | ||||||
|  |         } else { | ||||||
|  |             if sum > max { | ||||||
|  |                 max = sum; | ||||||
|  |             } | ||||||
|  |             sum = 0; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     println!("Max: {}", max); | ||||||
|  | } | ||||||
| @@ -12,3 +12,4 @@ | |||||||
| 9000 | 9000 | ||||||
|  |  | ||||||
| 10000 | 10000 | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user