Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advent of Code 2023
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 2023
Commits
e3cf24c2
Verified
Commit
e3cf24c2
authored
Dec 8, 2023
by
Falk Rehse
Browse files
Options
Downloads
Patches
Plain Diff
Day 6
parent
cd44603c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/day_6_1/mod.rs
+27
-0
27 additions, 0 deletions
src/day_6_1/mod.rs
src/day_6_2/mod.rs
+27
-0
27 additions, 0 deletions
src/day_6_2/mod.rs
src/main.rs
+3
-1
3 additions, 1 deletion
src/main.rs
with
57 additions
and
1 deletion
src/day_6_1/mod.rs
0 → 100644
+
27
−
0
View file @
e3cf24c2
use
crate
::
util
::
*
;
pub
fn
solve_from_str
(
input
:
&
str
)
->
u32
{
let
mut
lines
=
input
.lines
();
let
times
=
regex_positive_numbers
(
lines
.next
()
.unwrap
());
let
distances
=
regex_positive_numbers
(
lines
.next
()
.unwrap
());
let
mut
result
=
1
;
for
i
in
0
..
times
.len
()
{
let
mut
options
=
0
;
for
k
in
0
..
times
[
i
]
{
let
speed
=
k
;
let
distance
=
speed
*
(
times
[
i
]
-
k
);
if
distance
>
distances
[
i
]
{
options
+=
1
;
}
}
result
*=
options
;
}
result
}
This diff is collapsed.
Click to expand it.
src/day_6_2/mod.rs
0 → 100644
+
27
−
0
View file @
e3cf24c2
use
crate
::
util
::
*
;
pub
fn
solve_from_str
(
input
:
&
str
)
->
u64
{
let
mut
lines
=
input
.lines
();
let
times
=
regex_positive_numbers_u64
(
&
lines
.next
()
.unwrap
()
.replace
(
" "
,
""
));
let
distances
=
regex_positive_numbers_u64
(
&
lines
.next
()
.unwrap
()
.replace
(
" "
,
""
));
let
mut
result
=
1
;
for
i
in
0
..
times
.len
()
{
let
mut
options
=
0
;
for
k
in
0
..
times
[
i
]
{
let
speed
=
k
;
let
distance
=
speed
*
(
times
[
i
]
-
k
);
if
distance
>
distances
[
i
]
{
options
+=
1
;
}
}
result
*=
options
;
}
result
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
3
−
1
View file @
e3cf24c2
...
...
@@ -8,6 +8,8 @@ mod day_4_1;
mod
day_4_2
;
mod
day_5_1
;
mod
day_5_2
;
mod
day_6_1
;
mod
day_6_2
;
mod
util
;
...
...
@@ -16,7 +18,7 @@ use std::fs;
fn
main
()
{
let
input
=
fs
::
read_to_string
(
"input"
)
.expect
(
"Could not read input!"
);
let
solution
=
day_
5
_2
::
solve_from_str
(
input
.as_str
());
let
solution
=
day_
6
_2
::
solve_from_str
(
input
.as_str
());
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