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
e4b8d8e7
Verified
Commit
e4b8d8e7
authored
1 year ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Completed 2023 Day 01
parent
f0f55486
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
2023/python/Day01.py
+77
-0
77 additions, 0 deletions
2023/python/Day01.py
2023/python/DayXX
+1
-0
1 addition, 0 deletions
2023/python/DayXX
scaffolding/DayXX
+30
-0
30 additions, 0 deletions
scaffolding/DayXX
scaffolding/ImportData.TEMPLATE
+0
-0
0 additions, 0 deletions
scaffolding/ImportData.TEMPLATE
with
108 additions
and
0 deletions
2023/python/Day01.py
0 → 100644
+
77
−
0
View file @
e4b8d8e7
import
functools
from
typing
import
List
,
Optional
,
Dict
from
ImportData
import
import_data
day
:
int
=
1
# sample_data: List[str] = '''
# 1abc2
# pqr3stu8vwx
# a1b2c3d4e5f
# treb7uchet
# '''.split('\n')[1:-1]
sample_data
:
List
[
str
]
=
'''
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
'''
.
split
(
'
\n
'
)[
1
:
-
1
]
data_structure
:
type
=
List
[
str
]
def
parse_data
(
data
:
List
[
str
])
->
data_structure
:
return
data
def
part1
(
data
:
data_structure
)
->
int
:
values
:
List
[
int
]
=
[]
for
datum
in
data
:
first_digit
:
Optional
[
int
]
=
None
last_digit
:
int
=
0
for
character
in
datum
:
if
character
.
isdigit
():
first_digit
=
int
(
character
)
if
first_digit
is
None
else
first_digit
last_digit
=
int
(
character
)
if
first_digit
is
None
:
first_digit
=
0
last_digit
=
0
values
.
append
(
10
*
first_digit
+
last_digit
)
return
functools
.
reduce
(
lambda
a
,
b
:
a
+
b
,
values
)
def
part2
(
data
:
data_structure
)
->
int
:
digit_names
:
Dict
[
str
,
int
]
=
{
'
one
'
:
1
,
'
two
'
:
2
,
'
three
'
:
3
,
'
four
'
:
4
,
'
five
'
:
5
,
'
six
'
:
6
,
'
seven
'
:
7
,
'
eight
'
:
8
,
'
nine
'
:
9
,
'
zero
'
:
0
}
values
:
List
[
int
]
=
[]
for
datum
in
data
:
first_digit
:
Optional
[
int
]
=
None
last_digit
:
int
=
0
for
index
,
character
in
enumerate
(
datum
):
digit
:
Optional
[
int
]
=
None
if
character
.
isdigit
():
digit
=
int
(
character
)
else
:
for
digit_name
in
digit_names
:
if
datum
[
index
:
index
+
len
(
digit_name
)]
==
digit_name
:
digit
=
digit_names
[
digit_name
]
if
digit
is
not
None
:
first_digit
=
digit
if
first_digit
is
None
else
first_digit
last_digit
=
digit
if
first_digit
is
None
:
first_digit
=
0
last_digit
=
0
values
.
append
(
10
*
first_digit
+
last_digit
)
return
functools
.
reduce
(
lambda
a
,
b
:
a
+
b
,
values
)
if
__name__
==
'
__main__
'
:
production_ready
=
True
raw_data
=
import_data
(
day
)
if
production_ready
else
sample_data
print
(
part1
(
parse_data
(
raw_data
)))
print
(
part2
(
parse_data
(
raw_data
)))
This diff is collapsed.
Click to expand it.
2023/python/DayXX
0 → 120000
+
1
−
0
View file @
e4b8d8e7
../../scaffolding/DayXX
\ No newline at end of file
This diff is collapsed.
Click to expand it.
scaffolding/DayXX
0 → 100644
+
30
−
0
View file @
e4b8d8e7
from typing import List
from ImportData import import_data
day: int = X
sample_data: List[str] = [
]
data_structure: type = Y
def parse_data(data: List[str]) -> data_structure:
return None
def part1(data: data_structure) -> int:
return -1
def part2(data: data_structure) -> int:
return -1
if __name__ == '__main__':
production_ready = False
raw_data = import_data(day) if production_ready else sample_data
print(part1(parse_data(raw_data)))
print(part2(parse_data(raw_data)))
This diff is collapsed.
Click to expand it.
2020
/ImportData.TEMPLATE
→
scaffolding
/ImportData.TEMPLATE
+
0
−
0
View file @
e4b8d8e7
File moved
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