BRUN v 2
#1
Yeah I got my fake arrays working!

Code:
' and 1 for the monkey problem B.txt adopted for BRUN v2 to test string new string array functions get and put
' and 1 for the monkey problem.bas for JB 2.0 b 2018-02-11

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:
do
    n persn persn + 1
    if persn > 5
        exit
    fi
    n cc cc - 1
    n monk monk + 1
    put piel persn int(cc/5)
    n cc cc - int(cc/5)
    get p piel persn
    . For person persn , their pile is p
loop
.             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
do
    get p piel persn
    n p p + divee
    put piel persn p
    n persn persn +1
    if persn > 5
        exit
    fi
loop
n Remain start
n persn 1
do
    get p piel persn
    . For person persn , their pile is p
    n Remain Remain - p
    n persn persn + 1
    if persn > 5
        exit
    fi
loop
. The monkey has monk coconuts.
n Remain Remain - monk
.
. Coconuts remaining are Remain for the monkey who programmed this inventory.

BTW this line in code:
Dim pile(5)....

was totally ignored by BRUN as this line did not start with keyword!

In the other had all the lines that start with . are printed and all the variables in that line translated to their values.


Attached Files Thumbnail(s)

B += x
Reply
#2
Code:
simple sieve 2 B.txt for BRUN v 2 2018-02-14 adopted from:
'Simple sieve 2.bas SmallBASIC 2015-04-29 found a faster sieve with BASIC 256
n topLimit 1000
n limit topLimit ^ .5
. Primes to topLimit
take care of even numbers first
n index 4
do
    put composites index 1
    n index index + 2
    if index > topLimit
        exit
    fi
loop
now do odd numbers
n index 3
do
    get test composites index
    if test = 0
        if index < limit
            n j 2 * index
            do
                put composites j 1
                n j j + index
                if j > topLimit
                    exit
                fi
            loop
        fi
    fi
    n index index + 2
    if index > limit
        exit
    fi
loop
n index 2
pCount = 0
do
    get test composites index
    if test = 0
        n pCount pCount + 1
        . index
    fi    
    n index index +1
    if index > topLimit
        exit
    fi
loop
.
. There are pCount primes for the first topLimit integers.

Whoa! glacial slow but correct and no real array. Smile


Attached Files Thumbnail(s)

B += x
Reply