This program works out how many sheep dogs are required to look after a given number of black and white sheep.
Program
---
Sheep Dog Program
---
prog_vars =
d/white_sheep 0
d/black_sheep 0
d/total_sheep 0
d/runs_to_do 10
d/runs_done 1
d/colors[] ""
prog_vars.
prog_start =
print "Sheep Program."
print "No of runs to do /runs_to_do"
-- Setup the colors
/colors[1] "Black"
/colors[2] "White"
prog_start.
prog_loop =
-- Get more sheep, and see what color they are.
get_sheep -> /qty_of_sheep /color
"/runs_done > New Sheep qty /qty_of_sheep color /colors[/color]"
-- Check the type of sheep, update respective count
any /color = 1 ->
-- update black sheep
add /black_sheep /qty_of_sheep -> /black_sheep
else
-- update white sheep
add /white_sheep /qty_of_sheep -> /white_sheep
enda.
-- Update the total no of sheep
add /white_sheep /black_sheep -> /total_sheep
-- Check how many sheep dogs we need for the sheep
check_dogs /total_sheep -> /dogs_needed
-- Check if its time to exit yet
any /runs_done >= /runs_to_do ->
exitprog
enda.
-- Next run
inc /runs_done
prog_loop.
get_sheep -> /qty_of_sheep 0 /color 1 =
---
Returns a random quantity of sheep, of a random color.
---
rand 0 100 -> /qty_of_sheep
-- Get the color of this batch of sheep.
-- 1 = black 2 = white
rand 1 2 -> /color
get_sheep.
check_dogs /no_of_sheep 0 -> /dogs_needed 0 =
---
Calc the number of sheep dogs we need to manage this
many sheep. Return the no of dogs we need.
---
mul 0.1 /no_of_sheep -> /dogs_needed
check_dogs.
prog_stop =
-- display the final results
print "We need /dogs_needed dogs to manage them"
print "Total sheep /total_sheep"
print "Black /black_sheep White /white_sheep"
print "Exit Prog"
prog_stop.