Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advent of Coding
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Bohn
Advent of Coding
Commits
e3fe1fd7
Commit
e3fe1fd7
authored
2 years ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Completed Year 2022 Day 6 Part 1
parent
5e5d59b5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
2022/README.md
+14
-0
14 additions, 0 deletions
2022/README.md
2022/src/main/java/edu/unl/cse/bohn/year2022/Day6.java
+51
-0
51 additions, 0 deletions
2022/src/main/java/edu/unl/cse/bohn/year2022/Day6.java
with
65 additions
and
0 deletions
2022/README.md
+
14
−
0
View file @
e3fe1fd7
...
...
@@ -161,5 +161,19 @@ techniques should be used.
## Day 6
-
[
The problem
](
https://adventofcode.com/2022/day/6
)
-
[
The solution
](
src/main/java/edu/unl/cse/bohn/year2022/Day6.java
)
### Part 1
The subproblems are
-
Identify the first sequence of four unique characters in a string
-
Assume there is such a sequence
-
Determine when a sequence of four characters contain duplicates
-
Count the number of characters before the next character after that sequence
-
*i.e.*
, count the number of characters before that sequence plus the four characters in that sequence
## Day 7
(coming soon)
This diff is collapsed.
Click to expand it.
2022/src/main/java/edu/unl/cse/bohn/year2022/Day6.java
0 → 100644
+
51
−
0
View file @
e3fe1fd7
package
edu.unl.cse.bohn.year2022
;
import
edu.unl.cse.bohn.Puzzle
;
import
java.util.*
;
@SuppressWarnings
(
"unused"
)
public
class
Day6
extends
Puzzle
{
@SuppressWarnings
({
"SpellCheckingInspection"
,
"CommentedOutCode"
})
public
Day6
(
boolean
isProductionReady
)
{
super
(
isProductionReady
);
// sampleData = "mjqjpqmgbljsphdztnvjfqwrcgsmlb";
// sampleData = "bvwbjplbgvbhsrlpgdmjqwftvncz";
// sampleData = "nppdvjthqldpwncqszvftbrmjlhg";
// sampleData = "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg";
sampleData
=
"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"
;
}
@Override
public
long
computePart1
(
List
<
String
>
data
)
{
return
getStartOfPacketIndex
(
data
.
get
(
0
));
}
@Override
public
long
computePart2
(
List
<
String
>
data
)
{
return
0
;
}
private
long
getStartOfPacketIndex
(
String
dataStream
)
{
LinkedList
<
Character
>
markerCandidate
=
new
LinkedList
<>();
int
nextIndex
=
0
;
int
indexOfDuplicate
=
Integer
.
MIN_VALUE
;
boolean
foundMarker
=
false
;
while
(!
foundMarker
)
{
char
c
=
dataStream
.
charAt
(
nextIndex
++);
// System.out.print(markerCandidate + " + " + c + " = ");
int
indexOfPossibleDuplicate
=
markerCandidate
.
lastIndexOf
(
c
);
indexOfDuplicate
=
Integer
.
max
(
indexOfDuplicate
,
indexOfPossibleDuplicate
);
markerCandidate
.
add
(
c
);
if
(
nextIndex
>
4
)
{
markerCandidate
.
remove
();
indexOfDuplicate
--;
if
(
indexOfDuplicate
<
0
)
{
foundMarker
=
true
;
}
}
// System.out.println(markerCandidate);
}
return
nextIndex
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment