My son is doing a math worksheet. He is practicing the concept of 'carrying' when doing sums. The sheet has 16 problems, each is summing two threedigit numbers. What struck me as interesting was that the creator of the problems made every problem have at least two carries and most have three.
What is the probability distribution for the number of carries in finding the sum of two randomly selected threedigit numbers?
Feel free to generalize.
(In reply to
solution by Charlie)
DefDbl AZ
Dim crlf$, ct(3)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
mxtr = 1000000
For tr = 1 To mxtr
DoEvents
r1 = Int(Rnd(1) * 900) + 100
r2 = Int(Rnd(1) * 900) + 100
a1$ = LTrim(Str(r1))
a2$ = LTrim(Str(r2))
carryCt = 0: carry = 0
For p = 3 To 1 Step 1
d1 = Val(Mid(a1, p, 1))
d2 = Val(Mid(a2, p, 1))
s = d1 + d2 + carry
If s > 9 Then carry = 1: carryCt = carryCt + 1 Else carry = 0
Next
ct(carryCt) = ct(carryCt) + 1
Next tr
For c = 0 To 3
Text1.Text = Text1.Text & Str(ct(c))
Next
Text1.Text = Text1.Text & crlf
Text1.Text = Text1.Text & crlf & " done"
End Sub
produces
134550 342975 360366 162109
for counts of 0, 1, 2 or 3 carries adding two 3digit numbers.

Posted by Charlie
on 20170112 21:38:09 