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
832728e4
Verified
Commit
832728e4
authored
1 year ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Dabbling in Rust, 2023 Day 01
parent
e4b8d8e7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
2023/rust/Cargo.lock
+7
-0
7 additions, 0 deletions
2023/rust/Cargo.lock
2023/rust/Cargo.toml
+8
-0
8 additions, 0 deletions
2023/rust/Cargo.toml
2023/rust/src/main.rs
+36
-0
36 additions, 0 deletions
2023/rust/src/main.rs
with
51 additions
and
0 deletions
2023/rust/Cargo.lock
0 → 100644
+
7
−
0
View file @
832728e4
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "advent_of_code"
version = "0.1.0"
This diff is collapsed.
Click to expand it.
2023/rust/Cargo.toml
0 → 100644
+
8
−
0
View file @
832728e4
[package]
name
=
"advent_of_code"
version
=
"0.1.0"
edition
=
"2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
This diff is collapsed.
Click to expand it.
2023/rust/src/main.rs
0 → 100644
+
36
−
0
View file @
832728e4
fn
day01
(
data
:
Vec
<&
str
>
)
->
u32
{
let
mut
values
:
Vec
<
u32
>
=
Vec
::
new
();
for
datum
in
data
{
let
mut
first_digit
:
Option
<
u32
>
=
None
;
let
mut
last_digit
:
Option
<
u32
>
=
Option
::
from
(
0
);
for
character
in
datum
.chars
()
{
if
character
.is_digit
(
10
)
{
if
first_digit
==
None
{
first_digit
=
character
.to_digit
(
10
);
}
last_digit
=
character
.to_digit
(
10
);
}
}
if
first_digit
==
None
{
first_digit
=
Option
::
from
(
0
);
}
values
.push
(
10
*
first_digit
.expect
(
"this shouldn't happen"
)
+
last_digit
.expect
(
"this shouldn't happen"
));
}
let
mut
value
:
u32
=
0
;
return
loop
{
if
values
.is_empty
()
{
break
value
;
}
else
{
value
+=
values
.pop
()
.expect
(
"this really shouldn't happen"
);
}
}
}
fn
main
()
{
println!
(
"Hello, world!"
);
let
day01a_data
=
vec!
[
"1abc2"
,
"pqr3stu8vwx"
,
"a1b2c3d4e5f"
,
"treb7uchet"
];
let
day01b_data
=
vec!
[
"two1nine"
,
"eightwothree"
,
"abcone2threexyz"
,
"xtwone3four"
,
"4nineeightseven2"
,
"zoneight234"
,
"7pqrstsixteen"
];
println!
(
"{}"
,
day01
(
day01a_data
));
// day01(day01b_data);
}
\ No newline at end of file
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