Roger submitted a tiny-c program that is a "remake" of one I wrote in
March of last year. It contains several features that illustrate things
I would like to share with you.

His program may be seen at http://primepuzzle.com/tc/stickr.tc

This program "simulates" the following situation:



Take a stick and mark two spots at random places on it. Break the stick
at these places. See if you can then form a triangle with the three
pieces.

Imagine the stick miraculously reverting back to its original unbroken
state. Do the above again but of course the spots you mark will be
different.

Do this a bunch of times. Keep track of how many times you are actually
able to make a triangle.

Say you did this 1000 times. About how many triangles might you get
("give or take")?

In summary: What's the "probability" you can form a triangle when you
break a stick at two random spots on it?

The key idea behind all this is this: A triangle has the interesting and
important property that if you add the lengths of any two sides the sum will
always be bigger than the length of the third side.

It can be proved that the answer to this question is .25. An amazing
"geometric" proof of this fact may be seen at http://primepuzzle.com/tunxis/viviani.html.

Here's what Roger's program generated when I ran it.

C:\Users\Lee\MYSTUF~1\tc>tinyc

tiny-c/PC Interpreter  Version PC-01-07
Copyright (c) 1984 by Scott B. Guthery
Implemented 5/16/09 by Lee Bradley / Ed Davis

tiny-c Shell - 2/9/9

tc>.r stickr.tc
 1575
 0 67 1508 22992
tc>.[int q;for (q=1;q<=5;++q) [main]]

stickr.tc - rb - 2/1/2010

Enter a seed number. ==> 123

Enter number of sticks to break (1 to 3000). ==> 2789

Total sticks broken:  2789
Total triangles formed:  724

Probability of triangle = 0.2595

stickr.tc - rb - 2/1/2010

Enter a seed number. ==> 456

Enter number of sticks to break (1 to 3000). ==> 2345

Total sticks broken:  2345
Total triangles formed:  610

Probability of triangle = 0.2601

stickr.tc - rb - 2/1/2010

Enter a seed number. ==> 33

Enter number of sticks to break (1 to 3000). ==> 2134

Total sticks broken:  2134
Total triangles formed:  514

Probability of triangle = 0.2408

stickr.tc - rb - 2/1/2010

Enter a seed number. ==> 789

Enter number of sticks to break (1 to 3000). ==> 1890

Total sticks broken:  1890
Total triangles formed:  476

Probability of triangle = 0.2518

stickr.tc - rb - 2/1/2010

Enter a seed number. ==> 22

Enter number of sticks to break (1 to 3000). ==> 439

Total sticks broken:  439
Total triangles formed:  97

Probability of triangle = 0.2209

tc>

OK. I would now like to discuss some of the fine points in Roger's
program.

It works in DOS. By this I mean it works when you use the tiny-c
interpreter that most people would probably be using. There is a tiny-c
interpreter that works under Linux but a major difference between the
interpreters is that the Linux one uses so-called "long integers" and
the DOS one uses "short integers." My stick.tc program works in
the Linux environment. Roger's program is modeled after mine. The
differences between the two programs (and the similarities) reveal the
advantages (and disadvantages) of DOS and Linux.

I "tweaked" Roger's program in ways that are mostly "cosmetic." Here
is what I did:

A leading comment containing the name of the program, author's initials
and date was added.

A reference to a page on the internet which describes the problem being
solved was added.

I eliminated several assignment statements that initialized variables to
0. tiny-c variables are automatically initialized.

I merged two assignment statements into a single statement by taking
advantage of tiny-c's a=b=c construct (which puts what's in c in b and
then what's in b in a).

The program now displays the program's name, author and date when you
run it.

The maximum number of sticks to break was increased from 1000 to 3000.
This does two things: increases the accuracy of the simulation but
continues to keep the numbers small enough for "short integer"
calculations (i.e. under about 30000).