File tree 4 files changed +94
-0
lines changed
java/com/icecreamhead/adventofcode/q16
test/java/com/icecreamhead/adventofcode/q16
4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .icecreamhead .adventofcode .q16 ;
2
+
3
+ import java .util .HashSet ;
4
+ import java .util .List ;
5
+ import java .util .Set ;
6
+
7
+ public class TheFloorWillBeLava {
8
+
9
+ long part1 (char [][] input ) throws InterruptedException {
10
+ HashSet <Beam > beams = new HashSet <Beam >();
11
+ beams .add (Beam .START );
12
+ HashSet <Pos > visited = new HashSet <Pos >();
13
+
14
+ // print(input, beams);
15
+ while (!beams .isEmpty ()) {
16
+
17
+ for (Beam beam : beams ) {
18
+
19
+
20
+
21
+
22
+ }
23
+
24
+ break ;
25
+
26
+ // print(input, beams);
27
+ // Thread.sleep(1000);
28
+ }
29
+
30
+ return visited .size ();
31
+ }
32
+
33
+ private void print (char [][] input , Set <Beam > beams ) {
34
+ for (int y = 0 ; y < input .length ; y ++) {
35
+ for (int x = 0 ; x < input [y ].length ; x ++) {
36
+ if (has (beams , x , y ))
37
+ System .out .print ("#" );
38
+ else
39
+ System .out .print (input [y ][x ]);
40
+ }
41
+ System .out .println ();
42
+ }
43
+ System .out .println ();
44
+ }
45
+
46
+ private static boolean has (Set <Beam > beams , int x , int y ) {
47
+ return beams .stream ().anyMatch (b -> b .x () == x && b .y () == y );
48
+ }
49
+
50
+ enum Direction {
51
+ UP , DOWN , LEFT , RIGHT
52
+ }
53
+
54
+
55
+ private record Pos (int x , int y ) {}
56
+ private record Beam (Pos pos , Direction direction ) {
57
+ private static final Beam START = new Beam (new Pos (0 ,0 ), Direction .RIGHT );
58
+ private int x () {
59
+ return pos .x ;
60
+ }
61
+ private int y () {
62
+ return pos .y ;
63
+ }
64
+ }
65
+ }
Original file line number Diff line number Diff line change
1
+ .|...\....
2
+ |.-.\.....
3
+ .....|-...
4
+ ........|.
5
+ ..........
6
+ .........\
7
+ ..../.\\..
8
+ .-.-/..|..
9
+ .|....-|.\
10
+ ..//.|....
Original file line number Diff line number Diff line change
1
+ package com .icecreamhead .adventofcode .q16 ;
2
+
3
+ import com .icecreamhead .adventofcode .util .InputLoader ;
4
+ import org .assertj .core .api .Assertions ;
5
+ import org .junit .jupiter .api .Test ;
6
+
7
+ import static org .assertj .core .api .Assertions .assertThat ;
8
+ import static org .junit .jupiter .api .Assertions .*;
9
+
10
+ class TheFloorWillBeLavaTest {
11
+
12
+ private final TheFloorWillBeLava underTest = new TheFloorWillBeLava ();
13
+
14
+ private static final char [][] SAMPLE = InputLoader .loadGrid ("q16/sample.txt" );
15
+ @ Test
16
+ void part1_sample () throws InterruptedException {
17
+ assertThat (underTest .part1 (SAMPLE )).isEqualTo (46 );
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments