Atomic updates: Difference between revisions

no edit summary
(Added Kotlin)
No edit summary
Line 3,024:
9 (171429). (27 169 298 9 26 184 134 27 110 16 - 1000)
10 (192857). (54 80 38 52 29 14 42 173 246 272 - 1000)
</pre>
 
=={{header|Ring}}==
<lang ring>
# Project : Atomic updates
# Date : 2018/01/01
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.comsee
 
bucket = list(10)
f2 = 0
for i = 1 to 10
bucket[i] = floor(random(9)*10)
next
a = display("display:")
see nl
a = flatten(a)
see "" + a + nl
a = display("flatten:")
see nl
a = transfer(3,5)
see a + nl
see "19 from 3 to 5: "
a = display(a)
see nl
func display(a)
display = 0
see "" + a + " " + char(9)
for i = 1 to 10
display = display + bucket[i]
see "" + bucket[i] + " "
next
see " total:" + display
return display
func flatten(f)
f1 = floor((f / 10) + 0.5)
for i = 1 to 10
bucket[i] = f1
f2 = f2 + f1
next
bucket[10] = bucket[10] + f - f2
func transfer(a1,a2)
transfer = floor(random(9)/10 * bucket[a1])
bucket[a1] = bucket[a1] - transfer
bucket[a2] = bucket[a2] + transfer
</lang>
Output:
<pre>
display: 30 0 0 20 80 80 80 70 90 30 total:480
flatten: 48 48 48 48 48 48 48 48 48 48 total:480
19 from 3 to 5: 48 48 5 48 91 48 48 48 48 48 total:480
</pre>
 
2,468

edits