Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advent of Code 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Falk Rehse
Advent of Code 2022
Commits
fe56aee0
Commit
fe56aee0
authored
Dec 6, 2022
by
Falk Rehse
Browse files
Options
Downloads
Patches
Plain Diff
Day 6-2
parent
e062b49d
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
src/day_6_2/mod.rs
+27
-0
27 additions, 0 deletions
src/day_6_2/mod.rs
src/main.rs
+2
-1
2 additions, 1 deletion
src/main.rs
with
29 additions
and
1 deletion
src/day_6_2/mod.rs
0 → 100644
+
27
−
0
View file @
fe56aee0
const
SEQUENCE_LENGTH
:
usize
=
14
;
pub
fn
solve_from_str
(
input
:
&
str
)
->
usize
{
let
chars
:
Vec
<
char
>
=
input
.chars
()
.collect
();
for
i
in
0
..
chars
.len
()
-
4
{
if
!
check_for_duplicate
(
&
chars
,
i
,
SEQUENCE_LENGTH
)
{
return
i
+
SEQUENCE_LENGTH
;
}
}
panic!
(
"Expected to find section without duplicate!"
);
}
fn
check_for_duplicate
(
chars
:
&
Vec
<
char
>
,
index
:
usize
,
amount
:
usize
)
->
bool
{
let
mut
range
=
Vec
::
with_capacity
(
amount
);
for
i
in
index
..
index
+
amount
{
range
.push
(
chars
[
i
]);
}
range
.sort_unstable
();
range
.dedup
();
range
.len
()
!=
amount
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
2
−
1
View file @
fe56aee0
...
@@ -9,13 +9,14 @@ mod day_4_2;
...
@@ -9,13 +9,14 @@ mod day_4_2;
mod
day_5_1
;
mod
day_5_1
;
mod
day_5_2
;
mod
day_5_2
;
mod
day_6_1
;
mod
day_6_1
;
mod
day_6_2
;
use
std
::
fs
;
use
std
::
fs
;
fn
main
()
{
fn
main
()
{
let
input
=
fs
::
read_to_string
(
"input"
)
.expect
(
"Could not read input!"
);
let
input
=
fs
::
read_to_string
(
"input"
)
.expect
(
"Could not read input!"
);
let
solution
=
day_6_
1
::
solve_from_str
(
input
.as_str
());
let
solution
=
day_6_
2
::
solve_from_str
(
input
.as_str
());
println!
(
"Solution: {}"
,
solution
);
println!
(
"Solution: {}"
,
solution
);
}
}
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