FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adventofcode/src/main/java/AoC2015_11.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
/
AoC2015_11.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (77 loc) · 2.98 KB
Breadcrumbs
adventofcode
/
src
/
main
/
java
/
AoC2015_11.java
Copy path
File metadata and controls
94 lines (77 loc) · 2.98 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
85
86
87
88
89
90
91
92
93
94
import
static
com
.
github
.
pareronia
.
aoc
.
StringOps
.
nextLetter
;
import
java
.
util
.
List
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Sample
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
Samples
;
import
com
.
github
.
pareronia
.
aoc
.
solution
.
SolutionBase
;
public
class
AoC2015_11
extends
SolutionBase
<
String
,
String
,
String
> {
private
AoC2015_11
(
final
boolean
debug
) {
super
(
debug
);
}
public
static
final
AoC2015_11
create
() {
return
new
AoC2015_11
(
false
);
}
public
static
final
AoC2015_11
createDebug
() {
return
new
AoC2015_11
(
true
);
}
@
Override
protected
String
parseInput
(
final
List
<
String
>
inputs
) {
assert
inputs
.
size
() ==
1
;
return
inputs
.
get
(
0
);
}
@
Override
public
String
solvePart1
(
final
String
input
) {
return
PasswordGenerator
.
generateFrom
(
input
);
}
@
Override
public
String
solvePart2
(
final
String
input
) {
return
PasswordGenerator
.
generateFrom
(
PasswordGenerator
.
generateFrom
(
input
));
}
@
Override
@
Samples
({
@
Sample
(
method
=
"part1"
,
input
=
"abcdefgh"
,
expected
=
"abcdffaa"
),
@
Sample
(
method
=
"part1"
,
input
=
"ghijklmn"
,
expected
=
"ghjaabcc"
),
@
Sample
(
method
=
"part1"
,
input
=
"heqaabcc"
,
expected
=
"heqbbcdd"
),
})
public
void
samples
() {
}
public
static
void
main
(
final
String
[]
args
)
throws
Exception
{
assert
PasswordChecker
.
isOk
(
"heqaabcc"
.
toCharArray
()) ==
true
;
AoC2015_11
.
create
().
run
();
}
private
static
final
class
PasswordChecker
{
public
static
boolean
isOk
(
final
char
[]
password
) {
final
int
[]
pairs
=
new
int
[] { -
1
, -
1
};
boolean
trio
=
false
;
for
(
int
i
=
0
;
i
<
password
.
length
;
i
++) {
if
(
password
[
i
] ==
'i'
||
password
[
i
] ==
'o'
||
password
[
i
] ==
'l'
) {
return
false
;
}
if
(
i
>
0
&&
password
[
i
] ==
password
[
i
-
1
]) {
pairs
[
pairs
[
0
] == -
1
?
0
:
1
] =
i
;
}
trio
=
trio
||
i
<
password
.
length
-
3
&&
password
[
i
] ==
password
[
i
+
1
] -
1
&&
password
[
i
+
1
] ==
password
[
i
+
2
] -
1
;
}
return
trio
&&
pairs
[
0
] != -
1
&&
pairs
[
1
] != -
1
&&
password
[
pairs
[
0
]] !=
password
[
pairs
[
1
]];
}
}
private
static
final
class
PasswordGenerator
{
private
static
char
[]
increment
(
final
char
[]
password
,
final
int
i
) {
password
[
i
] =
nextLetter
(
password
[
i
],
1
);
if
(
password
[
i
] ==
'a'
) {
increment
(
password
,
i
-
1
);
}
return
password
;
}
public
static
String
generateFrom
(
final
String
password
) {
char
[]
chars
=
password
.
toCharArray
();
do
{
chars
=
increment
(
chars
,
chars
.
length
-
1
);
}
while
(!
PasswordChecker
.
isOk
(
chars
));
return
String
.
valueOf
(
chars
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL