Ooops
June 18, 2021, 06:42:29 AM

Author Topic: Sailors and coconuts problem  (Read 161 times)

Offline bplus

  • Full Member
  • ***
  • Posts: 183
Sailors and coconuts problem
« on: February 13, 2021, 06:40:51 AM »
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 start
dim 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 cc
n 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 start
n 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 AM by bplus »

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal