\section*{Problem \(3-341013=340913\)}

Karin and Rolf collect tram tickets. Each ticket has a number consisting of 6 digits. If the sum of the first three digits is equal to the sum of the last three digits, the ticket is called a lucky ticket.

To estimate the chance of this, Karin and Rolf want to know what percentage of all tickets are lucky tickets. It is assumed that each number from 000000 to 999999 occurs equally often.

Karin writes a simple computer program to determine the desired percentage by running an instruction sequence 1,000,000 times. Since this takes a long time, Rolf writes a program in which a (different) instruction sequence only needs to run 1,000 times (and only a few additional instructions need to be executed).

Write such a program for each of them and explain why the desired percentage can be found this way! (The choice of programming language is of course free.)
}

Two examples of programs of the mentioned type are:

1. Program:

```

z = 0
for a = 0 to 9
for b = 0 to 9
for c = 0 to 9
for d = 0 to 9
for e = 0 to 9
for f = 0 to 9
if a+b+c = d+e+f then z = z+1
next
next
next
next
next

```

```

1 4 next
15 print z/10000
2. Program:
dim n(27)
for s = 0 to 27
n(s) = 0
next
for a = 0 to 9
for b = 0 to 9
for c = 0 to 9
s = a+b+c
next
next
next
z = 0
for s = 0 to 27
z = z + n(s)*n(s)
next
print z/10000

```

In the 1st program, the statement 8, when the loops 2 - 7, 9 - 14 are followed, runs 1,000,000 times; it simply checks each of the numbers from 000000 to 999999 for the property \(a+b+c=d+e+f\). If it holds, the counting variable \(z\) (which is set to 0 at the beginning in 1) is incremented by 1. Thus, at the end, it gives the number of all "lucky ticket" numbers, so that in 15, one hundred times \(z / 1000000\) is printed as the desired percentage.

The 2nd program is based on the following consideration: For each number from 000000 to 999999, the sum \(s=a+b+c\) of the first three digits \(a, b, c\) is one of the numbers from 0 to 27. If a value \(s\) occurs exactly \(n(s)\) times as a sum among all 1000 groups of the first three digits, then it also occurs exactly \(n(s)\) times as a sum among all groups of the last three digits \(d, e, f\).

For exactly \((n(s) \cdot n(s))\) numbers, the property \(a+b+c=d+e+f\) holds specifically such that both equations \(a+b+c=s\) and \(d+e+f=s\) are satisfied for this value \(s\). Thus, it is proven:

The number \(z\) of all "lucky ticket" numbers is the sum of all products \((n(s) \cdot n(s))\) formed for \(s=0, \ldots, 27\).

The 2nd program calculates this sum: The determination of the frequencies \(n(s)\) occurs during the execution of 5 - 7, 10 - 12 of the instruction sequence 8, 9, where for each of the 1000 groups \(a b c\) from 000 to 999, the count \(n(s)\) of the relevant sum \(s=a+b+c\) is incremented by 1. (To prepare for this, all \(n(s)\) were set to 0 at the beginning in 1 - 4.) In 13 - 16, the sum of the products \((n(s) \cdot n(s))\) is formed from the thus obtained values \(n(s)\).

The calculated percentage is \(5.5252 \%\).
\footnotetext{