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
44db9ef4
Verified
Commit
44db9ef4
authored
1 year ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Completed 2023 Day 06
parent
0e9fa0fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
2023/python/Day06.py
+57
-0
57 additions, 0 deletions
2023/python/Day06.py
with
57 additions
and
0 deletions
2023/python/Day06.py
0 → 100644
+
57
−
0
View file @
44db9ef4
import
functools
import
itertools
from
typing
import
List
,
Tuple
from
ImportData
import
import_data
day
:
int
=
6
sample_data
:
List
[
str
]
=
'''
Time: 7 15 30
Distance: 9 40 200
'''
.
split
(
'
\n
'
)[
1
:
-
1
]
data_structure
:
type
=
List
[
Tuple
[
int
,
int
]]
def
parse_data1
(
data
:
List
[
str
])
->
data_structure
:
times
:
List
[
int
]
=
[
int
(
time
)
for
time
in
data
[
0
].
split
(
'
:
'
)[
1
].
strip
().
split
()]
distances
:
List
[
int
]
=
[
int
(
distance
)
for
distance
in
data
[
1
].
split
(
'
:
'
)[
1
].
strip
().
split
()]
tuples
=
[]
for
index
,
_
in
enumerate
(
times
):
tuples
.
append
((
times
[
index
],
distances
[
index
]))
return
tuples
def
get_number_of_winning_options
(
race
:
Tuple
[
int
,
int
])
->
int
:
time
:
int
=
race
[
0
]
record_distance
:
int
=
race
[
1
]
number_of_wins
:
int
=
0
for
hold_time
in
range
(
1
,
time
):
move_time
=
time
-
hold_time
speed
=
hold_time
distance
=
speed
*
move_time
if
distance
>
record_distance
:
number_of_wins
+=
1
return
number_of_wins
def
part1
(
data
:
data_structure
)
->
int
:
return
functools
.
reduce
(
lambda
x
,
y
:
x
*
y
,
[
get_number_of_winning_options
(
race
)
for
race
in
data
])
def
parse_data2
(
data
:
List
[
str
])
->
data_structure
:
times
:
List
[
str
]
=
[
time
for
time
in
data
[
0
].
split
(
'
:
'
)[
1
].
strip
().
split
()]
distances
:
List
[
str
]
=
[
distance
for
distance
in
data
[
1
].
split
(
'
:
'
)[
1
].
strip
().
split
()]
return
[((
int
(
''
.
join
(
times
))),
(
int
(
''
.
join
(
distances
))))]
def
part2
(
data
:
data_structure
)
->
int
:
return
get_number_of_winning_options
(
data
[
0
])
if
__name__
==
'
__main__
'
:
production_ready
=
True
raw_data
=
import_data
(
day
)
if
production_ready
else
sample_data
print
(
part1
(
parse_data1
(
raw_data
)))
print
(
part2
(
parse_data2
(
raw_data
)))
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