FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2016_03.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
/
AoC2016_03.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (64 loc) · 2.15 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2016_03.java
Copy path
File metadata and controls
77 lines (64 loc) · 2.15 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
import
static
com
.
github
.
pareronia
.
aoc
.
IntegerSequence
.
Range
.
range
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
List
;
import
com
.
github
.
pareronia
.
aoc
.
StringUtils
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Sample
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Samples
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
SolutionBase
;
public
class
AoC2016_03
extends
SolutionBase
<
int
[][],
Integer
,
Integer
> {
private
AoC2016_03
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
final
AoC2016_03
create
() {
return
new
AoC2016_03
(
false
);
}
public
static
final
AoC2016_03
createDebug
() {
return
new
AoC2016_03
(
true
);
}
@
Override
protected
int
[][]
parseInput
(
final
List
<
String
>
inputs
) {
return
inputs
.
stream
()
.
map
(
s
->
Arrays
.
stream
(
s
.
split
(
" "
))
.
filter
(
StringUtils
::
isNotBlank
)
.
mapToInt
(
Integer
::
parseInt
)
.
toArray
())
.
toArray
(
int
[][]::
new
);
}
@
Override
public
Integer
solvePart1
(
final
int
[][]
nums
) {
return
(
int
)
Arrays
.
stream
(
nums
)
.
map
(
t
->
new
Triangle
(
t
[
0
],
t
[
1
],
t
[
2
]))
.
filter
(
Triangle
::
valid
)
.
count
();
}
@
Override
public
Integer
solvePart2
(
final
int
[][]
nums
) {
return
range
(
0
,
nums
.
length
,
3
).
intStream
()
.
map
(
i
-> (
int
)
range
(
3
).
intStream
()
.
mapToObj
(
j
->
new
Triangle
(
nums
[
i
][
j
],
nums
[
i
+
1
][
j
],
nums
[
i
+
2
][
j
]))
.
filter
(
Triangle
::
valid
)
.
count
())
.
sum
();
}
@
Samples
({
@
Sample
(
method
=
"part1"
,
input
=
TEST1
,
expected
=
"0"
),
@
Sample
(
method
=
"part1"
,
input
=
TEST2
,
expected
=
"1"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST3
,
expected
=
"2"
),
})
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
AoC2016_03
.
create
().
run
();
}
private
static
final
String
TEST1
=
" 5 10 25"
;
private
static
final
String
TEST2
=
" 3 4 5"
;
private
static
final
String
TEST3
=
"""
5 3 6
10 4 8
25 5 10
"""
;
record
Triangle
(
int
a
,
int
b
,
int
c
) {
public
boolean
valid
() {
return
a
+
b
>
c
&&
a
+
c
>
b
&&
b
+
c
>
a
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL