FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2017_04.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_04.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (68 loc) · 2.74 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2017_04.java
Copy path
File metadata and controls
79 lines (68 loc) · 2.74 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
import
java
.
util
.
Arrays
;
import
java
.
util
.
List
;
import
java
.
util
.
function
.
Predicate
;
import
com
.
github
.
pareronia
.
aoc
.
Counter
;
import
com
.
github
.
pareronia
.
aoc
.
Utils
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Sample
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Samples
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
SolutionBase
;
public
final
class
AoC2017_04
extends
SolutionBase
<
List
<
String
>,
Integer
,
Integer
> {
private
AoC2017_04
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
AoC2017_04
create
() {
return
new
AoC2017_04
(
false
);
}
public
static
AoC2017_04
createDebug
() {
return
new
AoC2017_04
(
true
);
}
@
Override
protected
List
<
String
>
parseInput
(
final
List
<
String
>
inputs
) {
return
inputs
;
}
private
int
solve
(
final
List
<
String
>
input
,
final
Predicate
<
List
<
String
>>
strategy
) {
return
(
int
)
input
.
stream
()
.
map
(
s
->
Arrays
.
asList
(
s
.
split
(
" "
)))
.
filter
(
strategy
::
test
)
.
count
();
}
@
Override
public
Integer
solvePart1
(
final
List
<
String
>
input
) {
final
Predicate
<
List
<
String
>>
hasNoDuplicateWords
=
words
->
new
Counter
<>(
words
).
values
().
stream
().
noneMatch
(
v
->
v
>
1L
);
return
solve
(
input
,
hasNoDuplicateWords
);
}
@
Override
public
Integer
solvePart2
(
final
List
<
String
>
input
) {
final
Predicate
<
List
<
String
>>
hasNoAnagrams
=
words
->
words
.
size
() ==
words
.
stream
()
.
map
(
w
->
new
Counter
<>(
Utils
.
asCharacterStream
(
w
)))
.
distinct
().
count
();
return
solve
(
input
,
hasNoAnagrams
);
}
@
Samples
({
@
Sample
(
method
=
"part1"
,
input
=
TEST1
,
expected
=
"1"
),
@
Sample
(
method
=
"part1"
,
input
=
TEST2
,
expected
=
"0"
),
@
Sample
(
method
=
"part1"
,
input
=
TEST3
,
expected
=
"1"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST4
,
expected
=
"1"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST5
,
expected
=
"0"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST6
,
expected
=
"1"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST7
,
expected
=
"1"
),
@
Sample
(
method
=
"part2"
,
input
=
TEST8
,
expected
=
"0"
),
})
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
AoC2017_04
.
create
().
run
();
}
private
static
final
String
TEST1
=
"aa bb cc dd ee"
;
private
static
final
String
TEST2
=
"aa bb cc dd aa"
;
private
static
final
String
TEST3
=
"aa bb cc dd aaa"
;
private
static
final
String
TEST4
=
"abcde fghij"
;
private
static
final
String
TEST5
=
"abcde xyz ecdab"
;
private
static
final
String
TEST6
=
"a ab abc abd abf abj"
;
private
static
final
String
TEST7
=
"iiii oiii ooii oooi oooo"
;
private
static
final
String
TEST8
=
"oiii ioii iioi iiio"
;
}
Back
|
FazBrowse Home
|
New Git URL