Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
0
01-dec
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Advent Of Code
01-dec
Commits
3a9dcb6c
Commit
3a9dcb6c
authored
5 years ago
by
Kraijenoord
Browse files
Options
Downloads
Patches
Plain Diff
20191201
parent
4517d053
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
01-Alexander.py
+40
-0
40 additions, 0 deletions
01-Alexander.py
with
40 additions
and
0 deletions
01-Alexander.py
0 → 100644
+
40
−
0
View file @
3a9dcb6c
#This is the first assignment for advent of code
print
(
'
hoi
'
)
def
main
():
filepath
=
"
1-dec-input.txt
"
print
(
filepath
)
# open the input file
TotalFuel
=
0
with
open
(
filepath
)
as
fp
:
for
total
,
line
in
enumerate
(
fp
):
ModuleFuel
=
calcFuel
(
int
(
line
.
rstrip
()))
FuelFuel
=
calcExtraFuel
(
ModuleFuel
)
print
(
"
Zo veel Fuel voor de module en de fuel:
"
+
str
(
ModuleFuel
)
+
"
:
"
+
str
(
FuelFuel
))
TotalFuel
=
TotalFuel
+
ModuleFuel
+
FuelFuel
print
(
"
Zo veel in Fuel voor de mass:
"
+
str
(
TotalFuel
))
def
calcFuel
(
intMass
):
return
(
int
(
intMass
/
3
))
-
2
def
calcExtraFuel
(
intMass
):
RemainderFuel
=
0
ExtraFuel
=
intMass
while
ExtraFuel
>
0
:
ExtraFuel
=
max
(
0
,
calcFuel
(
ExtraFuel
))
RemainderFuel
=
RemainderFuel
+
ExtraFuel
return
RemainderFuel
if
__name__
==
"
__main__
"
:
main
()
#For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
#for a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
#For a mass of 1969, the fuel required is 654.
#For a mass of 100756, the fuel required is 33583.
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