FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2017_13.java at main · pareronia/adventofcode · GitHub
pareronia
/
adventofcode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2017_13.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (61 loc) · 2.17 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2017_13.java
Copy path
File metadata and controls
74 lines (61 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import
com
.
github
.
pareronia
.
aoc
.
MutableInt
;
import
com
.
github
.
pareronia
.
aoc
.
StringOps
;
import
com
.
github
.
pareronia
.
aoc
.
StringOps
.
StringSplit
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Sample
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Samples
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
SolutionBase
;
import
java
.
util
.
List
;
@
SuppressWarnings
({
"PMD.ClassNamingConventions"
,
"PMD.NoPackage"
})
public
final
class
AoC2017_13
extends
SolutionBase
<
List
<
AoC2017_13
.
Layer
>,
Integer
,
Integer
> {
private
AoC2017_13
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
AoC2017_13
create
() {
return
new
AoC2017_13
(
false
);
}
public
static
AoC2017_13
createDebug
() {
return
new
AoC2017_13
(
true
);
}
@
Override
protected
List
<
Layer
>
parseInput
(
final
List
<
String
>
inputs
) {
return
inputs
.
stream
().
map
(
Layer
::
fromInput
).
toList
();
}
private
boolean
caught
(
final
Layer
layer
,
final
int
delay
) {
return
(
delay
+
layer
.
depth
) % ((
layer
.
range
-
1
) *
2
) ==
0
;
}
@
Override
public
Integer
solvePart1
(
final
List
<
Layer
>
layers
) {
return
layers
.
stream
()
.
filter
(
layer
->
caught
(
layer
,
0
))
.
mapToInt
(
l
->
l
.
depth
*
l
.
range
)
.
sum
();
}
@
Override
public
Integer
solvePart2
(
final
List
<
Layer
>
layers
) {
final
MutableInt
delay
=
new
MutableInt
(
0
);
while
(
layers
.
stream
().
anyMatch
(
layer
->
caught
(
layer
,
delay
.
intValue
()))) {
delay
.
increment
();
}
return
delay
.
intValue
();
}
@
Samples
({
@
Sample
(
method
=
"part1"
,
input
=
TEST
,
expected
=
"24"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST
,
expected
=
"10"
),
})
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
create
().
run
();
}
private
static
final
String
TEST
=
"""
0: 3
1: 2
4: 4
6: 4
"""
;
record
Layer
(
int
depth
,
int
range
) {
public
static
Layer
fromInput
(
final
String
input
) {
final
StringSplit
sp
=
StringOps
.
splitOnce
(
input
,
": "
);
return
new
Layer
(
Integer
.
parseInt
(
sp
.
left
()),
Integer
.
parseInt
(
sp
.
right
()));
}
}
}
Back
|
FazBrowse Home
|
New Git URL