FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2017_10.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_10.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (57 loc) · 2.19 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2017_10.java
Copy path
File metadata and controls
69 lines (57 loc) · 2.19 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
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
com
.
github
.
pareronia
.
aoc
.
knothash
.
KnotHash
;
import
com
.
github
.
pareronia
.
aoc
.
knothash
.
KnotHash
.
State
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Sample
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Samples
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
SolutionBase
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
List
;
@
SuppressWarnings
({
"PMD.ClassNamingConventions"
,
"PMD.NoPackage"
})
public
final
class
AoC2017_10
extends
SolutionBase
<
String
,
Integer
,
String
> {
private
AoC2017_10
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
AoC2017_10
create
() {
return
new
AoC2017_10
(
false
);
}
public
static
AoC2017_10
createDebug
() {
return
new
AoC2017_10
(
true
);
}
@
Override
protected
String
parseInput
(
final
List
<
String
>
inputs
) {
return
inputs
.
getFirst
();
}
private
Integer
solve1
(
final
String
input
,
final
List
<
Integer
>
elements
) {
final
List
<
Integer
>
lengths
=
Arrays
.
stream
(
input
.
split
(
","
)).
map
(
Integer
::
valueOf
).
collect
(
toList
());
final
State
state
=
new
State
(
elements
,
lengths
,
0
,
0
);
final
State
ans
=
KnotHash
.
round
(
state
);
return
ans
.
elements
().
get
(
0
) *
ans
.
elements
().
get
(
1
);
}
@
Override
public
Integer
solvePart1
(
final
String
input
) {
return
solve1
(
input
,
new
ArrayList
<>(
KnotHash
.
SEED
));
}
@
Override
public
String
solvePart2
(
final
String
input
) {
return
KnotHash
.
hexString
(
input
);
}
@
Override
protected
void
samples
() {
final
AoC2017_10
test
=
createDebug
();
final
String
input
=
test
.
parseInput
(
List
.
of
(
"3,4,1,5"
));
assert
test
.
solve1
(
input
,
new
ArrayList
<>(
List
.
of
(
0
,
1
,
2
,
3
,
4
))) ==
12
;
}
@
Samples
({
@
Sample
(
method
=
"part2"
,
input
=
"AoC 2017"
,
expected
=
"33efeb34ea91902bb2f59c9920caa6cd"
),
@
Sample
(
method
=
"part2"
,
input
=
"1,2,3"
,
expected
=
"3efbe78a8d82f29979031a4aa0b16a9d"
),
@
Sample
(
method
=
"part2"
,
input
=
"1,2,4"
,
expected
=
"63960835bcdc130f0b66d7ff4f6a5a8e"
),
})
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
create
().
run
();
}
}
Back
|
FazBrowse Home
|
New Git URL