@@ -8,8 +8,7 @@ namespace AdventOfCode.Y2024.Day18;
8
8
[ ProblemName ( "RAM Run" ) ]
9
9
class Solution : Solver {
10
10
11
- public object PartOne ( string input ) =>
12
- Distance ( GetBlocks ( input ) , 1024 ) ;
11
+ public object PartOne ( string input ) => Distance ( GetBlocks ( input ) . Take ( 1024 ) ) ;
13
12
14
13
public object PartTwo ( string input ) {
15
14
// find the first block position that will cut off the goal position
@@ -19,7 +18,7 @@ public object PartTwo(string input) {
19
18
var ( lo , hi ) = ( 0 , blocks . Length ) ;
20
19
while ( hi - lo > 1 ) {
21
20
var m = ( lo + hi ) / 2 ;
22
- if ( Distance ( blocks , m ) == null ) {
21
+ if ( Distance ( blocks . Take ( m ) ) == null ) {
23
22
hi = m ;
24
23
} else {
25
24
lo = m ;
@@ -28,10 +27,10 @@ public object PartTwo(string input) {
28
27
return $ "{ blocks [ lo ] . Real } ,{ blocks [ lo ] . Imaginary } ";
29
28
}
30
29
31
- int ? Distance ( Complex [ ] blocks , int take ) {
30
+ int ? Distance ( IEnumerable < Complex > blocks ) {
32
31
// our standard priority queue based path finding
33
32
34
- var blocked = blocks . Take ( take ) . ToHashSet ( ) ;
33
+ var blockSet = blocks . ToHashSet ( ) ;
35
34
var size = 70 ;
36
35
var goal = size + size * Complex . ImaginaryOne ;
37
36
var q = new PriorityQueue < Complex , int > ( ) ;
@@ -45,7 +44,7 @@ public object PartTwo(string input) {
45
44
foreach ( var dir in new [ ] { 1 , - 1 , Complex . ImaginaryOne , - Complex . ImaginaryOne } ) {
46
45
var posT = pos + dir ;
47
46
if ( ! seen . Contains ( posT ) &&
48
- ! blocked . Contains ( posT ) &&
47
+ ! blockSet . Contains ( posT ) &&
49
48
0 <= posT . Imaginary && posT . Imaginary <= size &&
50
49
0 <= posT . Real && posT . Real <= size
51
50
) {
0 commit comments