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
d60a100c
Verified
Commit
d60a100c
authored
1 year ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up 2023 Day 01
parent
832728e4
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
2023/python/Day01.py
+31
-40
31 additions, 40 deletions
2023/python/Day01.py
scaffolding/DayXX
+3
-3
3 additions, 3 deletions
scaffolding/DayXX
with
34 additions
and
43 deletions
2023/python/Day01.py
+
31
−
40
View file @
d60a100c
...
...
@@ -5,14 +5,15 @@ from ImportData import import_data
day
:
int
=
1
# sample_data: List[str] = '''
# 1abc2
# pqr3stu8vwx
# a1b2c3d4e5f
# treb7uchet
# '''.split('\n')[1:-1]
sample_data
:
List
[
str
]
=
'''
sample_data
:
List
[
List
[
str
]]
=
[
'''
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
'''
.
split
(
'
\n
'
)[
1
:
-
1
]
,
'''
two1nine
eightwothree
abcone2threexyz
...
...
@@ -21,31 +22,12 @@ xtwone3four
zoneight234
7pqrstsixteen
'''
.
split
(
'
\n
'
)[
1
:
-
1
]
]
data_structure
:
type
=
List
[
str
]
data_structure
:
type
=
List
[
int
]
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
]
=
[]
...
...
@@ -67,11 +49,20 @@ def part2(data: data_structure) -> int:
first_digit
=
0
last_digit
=
0
values
.
append
(
10
*
first_digit
+
last_digit
)
return
functools
.
reduce
(
lambda
a
,
b
:
a
+
b
,
values
)
return
values
def
part1
(
data
:
data_structure
)
->
int
:
return
functools
.
reduce
(
lambda
a
,
b
:
a
+
b
,
data
)
def
part2
(
data
:
data_structure
)
->
int
:
return
functools
.
reduce
(
lambda
a
,
b
:
a
+
b
,
data
)
if
__name__
==
'
__main__
'
:
production_ready
=
True
raw_data
=
import_data
(
day
)
if
production_ready
else
sample_data
raw_data
=
import_data
(
day
)
if
production_ready
else
sample_data
[
0
]
print
(
part1
(
parse_data
(
raw_data
)))
raw_data
=
import_data
(
day
)
if
production_ready
else
sample_data
[
1
]
print
(
part2
(
parse_data
(
raw_data
)))
This diff is collapsed.
Click to expand it.
scaffolding/DayXX
+
3
−
3
View file @
d60a100c
...
...
@@ -4,9 +4,9 @@ from ImportData import import_data
day: int = X
sample_data: List[str] =
[
]
sample_data: List[str] =
'''
...
'''.split('\n')[1:-1
]
data_structure: type = Y
...
...
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