September 20, 2021, 14:52:19

### Author Topic: Sailors and coconuts problem  (Read 1023 times)

#### bplus

• Full Member
• Posts: 221
##### Sailors and coconuts problem
« on: February 13, 2021, 06:40:51 »
Hey I noticed this added to On-line Samples recently.

Yeah we played with this at JB when bluatigro presented the problem in his very broken English.

Cute! I called it, "And one for the Monkey Problem"

Here is my interpretation from my SmallBASIC inspired Interpreter allot of the descriptions are quotes from the blu:
Code: [Select]
`' and 1 for the monkey problem SB.txt rev for SB.exe 'from' and 1 for the monkey problem.bas for JB 2.0 b 2018-02-11' test string new string array functions > and <n start 100.   i (bluatigro) fount this puzle in a book:.     there are 5 person's + 1 monkey.     they shipwrek on a Island.     the fisrst day they colect kokonut's.. day 1:". I (bplus) am starting with a number of coconuts.n cc startdim pile(5) this is why we need string array! for 5 piles. Say the coconuts collected by the people is start ...     in the night happens this:.     (each) person goes to the pile.     divides it in 5 hides 1/5.     and gives 1 to the monkey.. I (bplus) am paying the monkey first.. I (bplus) am not cutting any coconuts into parts of coconuts... So Coconut inventory after first night:[ n persn persn + 1 i persn > 5 x f n cc cc - 1 n monk monk + 1 > piel persn int(cc/5) n cc cc - int(cc/5) < p piel persn . For person persn , their pile is p].             and monkey has monk.. day 2".      the 2e day".      thay divide the remaining pile in 5".      and give 1 to the monkey".      now calc the size of every pile".. Coconuts starting day 2, before final divvy is ccn cc cc - 1 n monk monk + 1     n divee int(cc/5). After monkey gets one more coconut the divvy is divee.n persn 1[ < p piel persn n p p + divee > piel persn p n persn persn +1 i persn > 5 x f]n Remain startn persn 1[ < p piel persn . For person persn , their pile is p n Remain Remain - p n persn persn + 1 i persn > 5 x f]. The monkey has monk coconuts.n Remain Remain - monk.. Coconuts remaining are Remain for the monkey who programmed this inventory.`
n means you are going to set a number varName varValueExpression.

You might figure out the rest

« Last Edit: February 13, 2021, 06:52:47 by bplus »

#### twgonder

• Jr. Member
• Posts: 29
##### Re: Sailors and coconuts problem
« Reply #1 on: June 30, 2021, 23:03:50 »
My first attempt in SmallBasic.

I am having some funny display problems. When I run this on ver 12.14 and 12.20 SDL
at the end a line seems to always come up missing in my tests.
Trial 3897 (the left most number) is always missing.

Is there a way to make sure that all print lines are displayed?
Is there a way to scroll up/down in the output (the mouse and page keys don't seem to work)?

Thanks
« Last Edit: July 02, 2021, 06:03:13 by twgonder »

#### round157

• Sr. Member
• Posts: 469
##### Re: Sailors and coconuts problem
« Reply #2 on: July 02, 2021, 10:26:06 »
My first attempt in SmallBasic.

Hello, new user?

The author(chrisw) of SmallBASIC does not come to the forum daily. However, there are several experienced users. They may solve the problem.

(Welcome to this forum!)

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #3 on: July 02, 2021, 11:35:02 »
My first attempt in SmallBasic.

I am having some funny display problems. When I run this on ver 12.14 and 12.20 SDL
at the end a line seems to always come up missing in my tests.
Trial 3897 (the left most number) is always missing.

Is there a way to make sure that all print lines are displayed?
Is there a way to scroll up/down in the output (the mouse and page keys don't seem to work)?

Thanks

If you get the print lines saved into an array you can make a scroller for array and show a page section at a time with arrow keys and page up/down keys, key home to go to start  and key end to last lines...

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #4 on: July 02, 2021, 11:45:58 »
In SB sample, the question asks what is minimum coconuts the sailors had to pick?

What is minimum picked to achieve what goal or specification?

The way I learned this riddle is: given they picked x amount of coconuts what is the amount of coconuts each sailor has after the final divy (and how many did the monkey get).

#### Aurel

• Sr. Member
• Posts: 349
##### Re: Sailors and coconuts problem
« Reply #5 on: July 02, 2021, 17:05:07 »
what i have is a flying monkey
so i am wondering maybe you can made something similar in SB
(Y)

#### twgonder

• Jr. Member
• Posts: 29
##### Re: Sailors and coconuts problem
« Reply #6 on: July 02, 2021, 20:33:18 »
The original problem that I gave coding applicants was simple and needed about six lines of actual code. Some poor guys wrote pages of code. Others snuck out of the testing room. The problem was something like this:

Five explorers go into the jungle to pick coconuts all day long. Back at camp they put them into a big pile and agreed to divide the pile up evenly in the morning. Explorer 1, awoke in the middle of the night, and not being a trusting sole, went to the pile, divided it into 5 smaller and equal piles, with one extra that he gave to a monkey that was watching. He hid his pile in the jungle, pushed the remaining four piles into one pile and went back to sleep. During the rest of the night, the other four explorers did the same pile division. In the morning all awoke to a much smaller pile than the evening before, but being unable to admit what they had each done, they divided the remaining pile into exactly five piles and went their separate ways. What is the minimum number of coconuts the explorers had to pick the day before?
(The first trick is to realize that you can't split a coconut five ways.)

From what I understand, this was a problem presented in an early 1900s university mathematics journal, long before computers were available to solve it. As I remember, there is a weird solution, but it results in a negative number of coconuts (not exactly a solution in my book).

I wrote this program to be more versatile and esthetic.

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #7 on: July 03, 2021, 12:25:12 »
Quote
What is the minimum number of coconuts the explorers had to pick the day before?
(The first trick is to realize that you can't split a coconut five ways.)

Again I ask, "What is the minimum number of coconuts the explorers had to pick the day before?"
to do what? Maybe for each explorer to leave with at least 1 coconut (total picked around 10) each explorer to have at least 10 coconuts? (Then it's closer to 100).

I agree you can't split coconuts so each time it is: take = INT(pile/numberOfExplorers).

I also agree that negative or imaginary numbers would not be satisfactory solutions for this problem.

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #8 on: July 03, 2021, 12:27:14 »
what i have is a flying monkey
so i am wondering maybe you can made something similar in SB

Ehhhh Aurel showing off his new graphics image for Micro A LOL! But can it do String Literals without quotes? LOL

Flying monkey phffff... simple shooter???
« Last Edit: July 03, 2021, 12:30:31 by bplus »

#### Aurel

• Sr. Member
• Posts: 349
##### Re: Sailors and coconuts problem
« Reply #9 on: July 03, 2021, 15:52:25 »
Yo ....you hit me with coconut in head..

String literals..wahat is that ?
You mean string variable ?
yes you can
(Y)

#### Aurel

• Sr. Member
• Posts: 349
##### Re: Sailors and coconuts problem
« Reply #10 on: July 03, 2021, 16:47:09 »
just for B+

(Y)

#### twgonder

• Jr. Member
• Posts: 29
##### Re: Sailors and coconuts problem
« Reply #11 on: July 03, 2021, 16:48:23 »

Again I ask, "What is the minimum number of coconuts the explorers had to pick the day before?"
to do what? Maybe for each explorer to leave with at least 1 coconut (total picked around 10) each explorer to have at least 10 coconuts? (Then it's closer to 100).

Let's start with your 10. Divide it into 5 piles of two coconuts. Oooops, there isn't one for the monkey.
Let's try a pile of 11. We get 5 piles of two and one for the monkey. So far, so good. Push four piles remaining (after hiding one) together for one pile of 8. The next explorer divides 8 by 5, Oooops, no 5 equal piles.
Now you can try again with 12 coconuts. Keep trying till you find a solution to the problem as stated.
(There is no other "to do what?")
« Last Edit: July 03, 2021, 18:29:10 by twgonder »

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #12 on: July 03, 2021, 21:37:15 »
I have each explorer pay the monkey a coconut first so it doesn't raise hell while they take an integer amount of 1/5th the pile for 5 explorers.

So I need at least 17 coconuts for everyone to walk away with at least one coconut.

From a JB run coded 2018 (the following assumes 5 explorers/sailors):
Quote
i (bluatigro) fount this puzle in a book :
there are 5 person's + 1 monkey
they shipwrek on a Island
the fisrst day they colect kokonut's

day 1:
I (bplus) am starting with a number of coconuts.
Say the coconuts collected by the people is 17.

in the night happens this :
eats (each) person goes to the pile
divides it in 5 hides 1/5
and gives 1 to the monkey

I (bplus) am paying the monkey first.
I (bplus) am not cutting any coconuts into parts of coconuts.

So Coconut inventory after first night:
For person 1, their pile is 3
For person 2, their pile is 2
For person 3, their pile is 1
For person 4, their pile is 1
For person 5, their pile is 1
and monkey has 5

day 2
the 2e day
thay divide the remaining pile in 5
and give 1 to the monkey
now calc the size of every pile

Coconuts starting day 2, before final divy is 4
after monkey gets one more coconut the divy is 0

For person 1, their pile is 3
For person 2, their pile is 2
For person 3, their pile is 1
For person 4, their pile is 1
For person 5, their pile is 1
The monkey has 6 coconuts.

Coconuts remaining are 3 for the monkey who programmed this inventory.

So @twgonder how many coconuts do you think is needed to be collected so that everyone walks away with at least 1 coconut?
« Last Edit: July 03, 2021, 21:44:35 by bplus »

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #13 on: July 03, 2021, 22:03:02 »
I need 22 coconuts before none get wasted at the end everyone walks away with at least 2:
Quote
i (bluatigro) fount this puzle in a book :
there are 5 person's + 1 monkey
they shipwrek on a Island
the fisrst day they colect kokonut's

day 1:
I (bplus) am starting with a number of coconuts.
Say the coconuts collected by the people is 22.

in the night happens this :
eats (each) person goes to the pile
divides it in 5 hides 1/5
and gives 1 to the monkey

I (bplus) am paying the monkey first.
I (bplus) am not cutting any coconuts into parts of coconuts.

So Coconut inventory after first night:
For person 1, their pile is 4
For person 2, their pile is 3
For person 3, their pile is 2
For person 4, their pile is 1
For person 5, their pile is 1
and monkey has 5

day 2
the 2e day
thay divide the remaining pile in 5
and give 1 to the monkey
now calc the size of every pile

Coconuts starting day 2, before final divy is 6
after monkey gets one more coconut the divy is 1

For person 1, their pile is 5
For person 2, their pile is 4
For person 3, their pile is 3
For person 4, their pile is 2
For person 5, their pile is 2
The monkey has 6 coconuts.

Coconuts remaining are 0 for the monkey who programmed this inventory.

#### bplus

• Full Member
• Posts: 221
##### Re: Sailors and coconuts problem
« Reply #14 on: July 03, 2021, 22:10:35 »
Yo ....you hit me with coconut in head..

String literals..wahat is that ?
You mean string variable ?
yes you can

Yo = "This is a string literal."

Yo is a string variable set to the string literal right of = sign.

In my Interpreter you can do this without double quotes:
Yo = This is a string literal.

This is print Yo code:
. Yo

Output is:
This is a string literal.

« Last Edit: July 03, 2021, 22:12:38 by bplus »