Day 01
This commit is contained in:
		
							parent
							
								
									2b7a4d97fd
								
							
						
					
					
						commit
						f9b3e9214b
					
				
					 6 changed files with 54 additions and 0 deletions
				
			
		
							
								
								
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,9 +1,11 @@ | |||
| .history/ | ||||
| # ---> Rust | ||||
| # Generated by Cargo | ||||
| # will have compiled files and executables | ||||
| debug/ | ||||
| target/ | ||||
| 
 | ||||
| 
 | ||||
| # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||||
| # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||||
| Cargo.lock | ||||
|  | @ -14,3 +16,5 @@ Cargo.lock | |||
| # MSVC Windows builds of rustc generate these, which store debugging information | ||||
| *.pdb | ||||
| 
 | ||||
| # AoC | ||||
| input/ | ||||
							
								
								
									
										10
									
								
								Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Cargo.toml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| [package] | ||||
| name = "aoc_2022" | ||||
| version = "0.1.0" | ||||
| edition = "2021" | ||||
| 
 | ||||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||
| 
 | ||||
| [dependencies] | ||||
| aoc-runner = "0.3.0" | ||||
| aoc-runner-derive = "0.3.0" | ||||
							
								
								
									
										19
									
								
								src/day01.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/day01.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| use std::cmp::Reverse; | ||||
| 
 | ||||
| use aoc_runner_derive::{aoc, aoc_generator}; | ||||
| #[aoc_generator(day1)] | ||||
| pub fn input_generator(input: &str) -> Vec<usize> { | ||||
|     input.split("\n\n").map(|chunk| chunk.lines().map(|line| line.trim().parse::<usize>().unwrap()).sum()).collect() | ||||
| } | ||||
| 
 | ||||
| #[aoc(day1, part1)] | ||||
| pub fn solve_part1(input: &[usize]) -> usize { | ||||
|     input.iter().max().copied().unwrap_or(0) | ||||
| } | ||||
| 
 | ||||
| #[aoc(day1, part2)] | ||||
| pub fn solve_part2(input: &[usize]) -> usize { | ||||
|     let mut scores: Vec<usize> = input.to_vec(); | ||||
|     scores.sort_by_key(|v| Reverse(*v)); | ||||
|     scores.iter().take(3).sum() | ||||
| } | ||||
							
								
								
									
										15
									
								
								src/dayXX.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/dayXX.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| use aoc_runner_derive::{aoc, aoc_generator}; | ||||
| #[aoc_generator(dayX)] | ||||
| pub fn input_generator(input: &str) -> _ { | ||||
|     todo!() | ||||
| } | ||||
| 
 | ||||
| #[aoc(dayX, part1)] | ||||
| pub fn solve_part1(input: &[usize]) -> _ { | ||||
|     todo!() | ||||
| } | ||||
| 
 | ||||
| // #[aoc(dayX, part2)]
 | ||||
| // pub fn solve_part2(input: &[usize]) -> _ {
 | ||||
| //     todo!()
 | ||||
| // }
 | ||||
							
								
								
									
										4
									
								
								src/lib.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/lib.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | |||
| 
 | ||||
| use aoc_runner_derive::aoc_lib; | ||||
| pub mod day01; | ||||
| aoc_lib! { year = 2022 } | ||||
							
								
								
									
										2
									
								
								src/main.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/main.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| use aoc_runner_derive::aoc_main; | ||||
| aoc_main! { lib  = aoc_2022 } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue