Compare commits
	
		
			No commits in common. "b522357495aef44d039ea2cf2dbc28f29248da66" and "1277882310430e4914201b9fd9fdea8066f1d98d" have entirely different histories.
		
	
	
		
			b522357495
			...
			1277882310
		
	
		
							
								
								
									
										30
									
								
								aoc_2024/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										30
									
								
								aoc_2024/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -11,12 +11,6 @@ dependencies = [ | ||||
|  "memchr", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "allocator-api2" | ||||
| version = "0.2.21" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "aoc-runner" | ||||
| version = "0.3.0" | ||||
| @ -52,7 +46,6 @@ version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "aoc-runner", | ||||
|  "aoc-runner-derive", | ||||
|  "hashbrown", | ||||
|  "nom", | ||||
|  "num", | ||||
|  "regex", | ||||
| @ -65,29 +58,6 @@ version = "1.4.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "equivalent" | ||||
| version = "1.0.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "foldhash" | ||||
| version = "0.1.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "hashbrown" | ||||
| version = "0.15.2" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" | ||||
| dependencies = [ | ||||
|  "allocator-api2", | ||||
|  "equivalent", | ||||
|  "foldhash", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "itoa" | ||||
| version = "1.0.14" | ||||
|  | ||||
| @ -6,7 +6,6 @@ edition = "2021" | ||||
| [dependencies] | ||||
| aoc-runner = "0.3.0" | ||||
| aoc-runner-derive = "0.3.0" | ||||
| hashbrown = "0.15.2" | ||||
| nom = "7.1.3" | ||||
| num = "0.4.3" | ||||
| regex = "1.11.1" | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| use hashbrown::{HashMap, HashSet}; | ||||
| use std::collections::{HashMap, HashSet}; | ||||
| 
 | ||||
| use aoc_runner_derive::{aoc, aoc_generator}; | ||||
| use num::integer::gcd; | ||||
| @ -15,9 +15,11 @@ fn parse(input: &str) -> Input { | ||||
|             .enumerate() | ||||
|             .filter(|(_, c)| c != &'.') | ||||
|             .for_each(|(x, c)| { | ||||
|                 map.entry(c) | ||||
|                     .or_insert(Vec::new()) | ||||
|                     .push((x as isize, y as isize)); | ||||
|                 if let std::collections::hash_map::Entry::Vacant(e) = map.entry(c) { | ||||
|                     e.insert(vec![(x as isize, y as isize)]); | ||||
|                 } else { | ||||
|                     map.get_mut(&c).unwrap().push((x as isize, y as isize)); | ||||
|                 } | ||||
|             }); | ||||
|     }); | ||||
|     let vec = map.into_values().collect(); | ||||
| @ -48,7 +50,7 @@ fn part1(input: &Input) -> usize { | ||||
| 
 | ||||
| #[aoc(day8, part2)] | ||||
| fn part2(input: &Input) -> usize { | ||||
|     let mut set = HashSet::with_capacity(input.1.len() * input.1.len()); | ||||
|     let mut set = HashSet::new(); | ||||
|     input.1.iter().for_each(|vec| { | ||||
|         for l in 0..vec.len() { | ||||
|             for r in l + 1..vec.len() { | ||||
| @ -56,6 +58,7 @@ fn part2(input: &Input) -> usize { | ||||
|                 let a2 = vec[r]; | ||||
|                 let s = a1; | ||||
|                 let v = (a2.0 - a1.0, a2.1 - a1.1); | ||||
|                 let v = (v.0 / gcd(v.0, v.1), v.1 / gcd(v.0, v.1)); | ||||
|                 let mut d = 0; | ||||
|                 loop { | ||||
|                     let c = (s.0 + d * v.0, s.1 + d * v.1); | ||||
| @ -66,7 +69,7 @@ fn part2(input: &Input) -> usize { | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|                 let mut d = -1; | ||||
|                 let mut d = 0; | ||||
|                 loop { | ||||
|                     let c = (s.0 + d * v.0, s.1 + d * v.1); | ||||
|                     d -= 1; | ||||
| @ -79,6 +82,12 @@ fn part2(input: &Input) -> usize { | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
|     // for y in 0..input.0 .1 {
 | ||||
|     //     println!();
 | ||||
|     //     for x in 0..input.0 .0 {
 | ||||
|     //         print!("{}", if set.contains(&(x, y)) { '#' } else { '.' })
 | ||||
|     //     }
 | ||||
|     // }
 | ||||
|     set.len() | ||||
| } | ||||
| 
 | ||||
| @ -104,7 +113,5 @@ mod tests { | ||||
|             )), | ||||
|             34 | ||||
|         ); | ||||
| 
 | ||||
|         assert_eq!(part2(&parse(include_str!("../input/2024/day8.txt"))), 1017); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user