FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2025_05.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
/
AoC2025_05.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (71 loc) · 2.61 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2025_05.java
Copy path
File metadata and controls
84 lines (71 loc) · 2.61 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
75
76
77
78
79
80
81
82
83
84
import
com
.
github
.
pareronia
.
aoc
.
RangeInclusive
;
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
.
HashSet
;
import
java
.
util
.
List
;
import
java
.
util
.
Set
;
@
SuppressWarnings
({
"PMD.ClassNamingConventions"
,
"PMD.NoPackage"
})
public
final
class
AoC2025_05
extends
SolutionBase
<
AoC2025_05
.
Database
,
Long
,
Long
> {
private
AoC2025_05
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
AoC2025_05
create
() {
return
new
AoC2025_05
(
false
);
}
public
static
AoC2025_05
createDebug
() {
return
new
AoC2025_05
(
true
);
}
@
Override
protected
Database
parseInput
(
final
List
<
String
>
inputs
) {
return
Database
.
fromInput
(
inputs
);
}
@
Override
public
Long
solvePart1
(
final
Database
database
) {
return
database
.
availableIds
().
stream
()
.
filter
(
pid
->
database
.
idRanges
().
stream
().
anyMatch
(
rng
->
rng
.
contains
(
pid
)))
.
count
();
}
@
Override
public
Long
solvePart2
(
final
Database
database
) {
return
database
.
idRanges
().
stream
()
.
mapToLong
(
rng
->
rng
.
getMaximum
() -
rng
.
getMinimum
() +
1
)
.
sum
();
}
@
Samples
({
@
Sample
(
method
=
"part1"
,
input
=
TEST
,
expected
=
"3"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST
,
expected
=
"14"
),
})
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
create
().
run
();
}
private
static
final
String
TEST
=
"""
3-5
10-14
16-20
12-18
1
5
8
11
17
32
"""
;
record
Database
(
List
<
RangeInclusive
<
Long
>>
idRanges
,
List
<
Long
>
availableIds
) {
public
static
Database
fromInput
(
final
List
<
String
>
inputs
) {
final
List
<
List
<
String
>>
blocks
=
StringOps
.
toBlocks
(
inputs
);
final
Set
<
RangeInclusive
<
Long
>>
idRanges
=
new
HashSet
<>();
for
(
final
String
line
:
blocks
.
getFirst
()) {
final
StringSplit
split
=
StringOps
.
splitOnce
(
line
,
"-"
);
idRanges
.
add
(
RangeInclusive
.
between
(
Long
.
parseLong
(
split
.
left
()),
Long
.
parseLong
(
split
.
right
())));
}
final
List
<
Long
>
availableIds
=
blocks
.
getLast
().
stream
().
map
(
Long
::
parseLong
).
toList
();
return
new
Database
(
RangeInclusive
.
mergeRanges
(
idRanges
),
availableIds
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL