Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
coconuts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Zach Ingbretsen
coconuts
Commits
a2a55fc3
Commit
a2a55fc3
authored
5 years ago
by
La Fée Verte
Browse files
Options
Downloads
Patches
Plain Diff
adding the description`
parent
5bf9d660
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
coco.py
+16
-1
16 additions, 1 deletion
coco.py
coconuts.txt
+36
-0
36 additions, 0 deletions
coconuts.txt
with
52 additions
and
1 deletion
coco.py
+
16
−
1
View file @
a2a55fc3
#!/usr/bin/python3
running_count
=
[
0
,
0
,
0
,
0
,
0
]
def
splitthem
(
quant
):
"""
take a quantity and return False if it is not one more than
...
...
@@ -11,6 +11,11 @@ def splitthem(quant):
if
quant
[
0
]
%
5
!=
1
:
return
False
else
:
t
=
quant
[
0
]
//
5
for
k
in
range
(
5
):
if
running_count
[
k
]
==
0
:
running_count
[
k
]
=
t
break
quant
[
0
]
-=
(
1
+
quant
[
0
]
//
5
)
return
True
...
...
@@ -29,6 +34,8 @@ def testnum(num):
return
False
if
num
[
0
]
%
5
==
0
:
for
i
in
range
(
5
):
running_count
[
i
]
+=
num
[
0
]
//
5
return
True
else
:
return
False
...
...
@@ -46,9 +53,17 @@ def main():
num
=
[
0
]
for
n
in
range
(
1
,
TESTQUANTITY
):
for
i
in
range
(
5
):
running_count
[
i
]
=
0
num
[
0
]
=
n
if
testnum
(
num
):
print
(
"
The Number Was %d
"
%
n
)
print
(
running_count
)
total
=
0
for
i
in
running_count
:
total
+=
i
print
(
total
)
return
print
(
"
Not found in %d tries.
"
%
TESTQUANTITY
)
...
...
This diff is collapsed.
Click to expand it.
coconuts.txt
0 → 100644
+
36
−
0
View file @
a2a55fc3
Five guys get shipwrecked on a deserted island. They start off friendly and
spend the whole day collecting all the coconuts they can find. By the time it
gets dark they have gotten on each other's nerves to the point that they decide
to divey up their cocounts and go their separate ways. Since it has gotten
dark, they decide that they will sleep and take care of the details in the
morning.
A little while after they all go to bed, one of them wakes up and decides that
he doesn't trust the rest of them not to take all the coconuts for themselves
and leave him out cold. So he goes to the pile, meticulously separates the
coconuts into 5 perfectly equal piles and finds that there is one left over, so
he tosses that one to a local monkey who just happened to be watching him with
some curiousity. He then takes his fair 1/5 back to his bunk and squishes the
pile back together. Then he goes back to his bunk and goes to sleep.
By the time he falls back to sleep a second guy wakes up and has the same exact
concern. He executes the same separation on the pile that is left. When he
splits it into 5 piles, he also finds that there is one left over, and again
tosses the extra one to the monkey. Then he takes his fair 1/5, pushes the rest
of the pile back together stows his coconuts in his bunk and then he goes back
to sleep.
As you can guess, the next 3 guys all go through the same scenario, each of
them finding exactly 1 extra coconut to the delight of the waiting monkey. Each
take their fair 1/5 of the remaining coconuts and go back to sleep.
In the light of morning, none of them is going to admit to their nocturnal
excursions so they split the pile into 5 and amazingly, to the chagrin
of the monkey, there was no extra one this time. They each take their pile, and
the ones they collected during the night and went about their way never to be
seen again.
The puzzle is to determine what is the minimum possible number of coconuts that
they started with in the pile at the beginning of the night?
Extra credit if you can determine how many each of them ended up with?
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