Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Atomic-updates/Run-BASIC/atomic-updates.basic
Normal file
34
Task/Atomic-updates/Run-BASIC/atomic-updates.basic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
DIM bucket(10)
|
||||
FOR i = 1 TO 10 : bucket(i) = int(RND(0)*100) : NEXT
|
||||
|
||||
a = display(" Display:") ' show original array
|
||||
a = flatten(a) ' flatten the array
|
||||
a = display(" Flatten:") ' show flattened array
|
||||
a = transfer(3,5) ' transfer some amount from 3 to 5
|
||||
a = display(a;" from 3 to 5:") ' Show transfer array
|
||||
end
|
||||
|
||||
FUNCTION display(a$)
|
||||
print a$;" ";chr$(9);
|
||||
for i = 1 to 10
|
||||
display = display + bucket(i)
|
||||
print bucket(i);chr$(9);
|
||||
next i
|
||||
print " Total:";display
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION flatten(f)
|
||||
f1 = int((f / 10) + .5)
|
||||
for i = 1 to 10
|
||||
bucket(i) = f1
|
||||
f2 = f2 + f1
|
||||
next i
|
||||
bucket(10) = bucket(10) + f - f2
|
||||
END FUNCTION
|
||||
|
||||
|
||||
FUNCTION transfer(a1,a2)
|
||||
transfer = int(rnd(0) * bucket(a1))
|
||||
bucket(a1) = bucket(a1) - transfer
|
||||
bucket(a2) = bucket(a2) + transfer
|
||||
END FUNCTION
|
||||
Loading…
Add table
Add a link
Reference in a new issue