April 8, 2012

Delphi For Fun Newsletter #63

Welcome to spring time!  Now that everything is in bloom, we're working to protect the grape vines and blueberries from freezing for a couple of days.   We just returned from a Caribbean  cruise with family which provided an excuse on sea days  to write a Sudoku helper/solver  for the puzzles that the cruise line handed out daily.  The ports provided opportunities for swimming, snorkeling, zip-lining with a little bit of history thrown in for good measure.  I'll need most of April to recover!  

In the meantime, January, February, and March were relatively productive with over a range of topics.  Here are the  postings for the  quarter.    

---------------------------------------------------------------------------------

January 11, 2012: Robot Rooms implements an algorithm for exactly covering a rectangular area with random rectangles meeting certain size and shape constraints.  Earlier exact covering algorithms tended to generate many long and skinny rectangles or with a large range of sizes. Neither of those properties are  desired if we want to design dungeons or  rooms for robots to explore!.
 

January 12, 2012: Logic Solver is  a program which can help solve many logic problems commonly found in puzzle magazines and books.  Here is a simple example: 

Mary, John and Pete have red, brown, and blonde hair, and are 13, 14, and 15 years old .  Using the following clues determine the hair color, and age of each child.
1. The youngest has blonde hair.
2. John is older than Pete.
3. John does not have red hair and Pete does not have blonde hair.

From these facts the program can apply rules of logic to match the children up with their ages and hair color.  Previous versions would handle up to 100 facts; Logic Solver Version 3.3 posted the other day solves problems at least twice as large as the  previous version.   Click the link to see the rest of the story.

January 18, 2012: 

A Delphi programmer  recently requested information about determining the slope of the regression line through a set of (X, Y) data points.  It seemed like something I must have written and posted in the 11 years the site has been around but that doesn't seem to be the case.  So here is LinearLeastSquares which takes a set of points, plots them and draws the "best fit" regression line.  It also displays the equation of the line and Correlation Coefficient, R (actually R2, called the  Coefficient of Determination) indicating how well the data are linearly related.   In the chart a right the (X, Y) data points are: (1.1,2.1), (2.3,3.9), (3.7,6.1), (3.9,7.9),  (4.0,9.0), and  (5.0,11.0). The "Best Fit" line for this data is Y=2.3X-1.0 and   R2=0.9384
  

January 27, 2012:  Here are a couple of interesting probability problems solved analytically (describing the logic leading to the solution) and experimentally (running a million trials of a simulation model),    Fifty Probability Problems presents  two problems  about ladder tournaments.  Plans are to add more of the 50 in the future. 
 

February 7, 2012:  Here are two more probability problem solvers which I found more interesting than anything else I had to work on this week. Fifty Probability Problems,  Version 4 was added today:

    Problem 18: If 100 coins are tossed, what is the probability that exactly 50 heads will be showing?

    Problem 19: Samuel Pepys wrote Isaac Newton to ask which of these events is more likely: that a person get (a) at least 1 six when 6 dice are rolled. (b) at least 2 sixes when 12 dice are rolled, or (c) at least 3 sixes when 18 dice are rolled.  What is the answer?

February 21, 2012:  I've spent much of the past couple of weeks travel planning for our next family cruise in March during the grandkids' spring break.  Zip lining in St. Kitts - whoopee!

 I spent most of my programming time on a dead end (so far) effort to create a program to start or stop&restart a program based on a schedule or CPU or memory usage.  I need this to workaround a commercial weather system program which crashes periodically because it has a memory leak.

In the end, I decided to tackle another problem from the Fifty Probability Programs book I'm working my way through.  This one about a three way "duel"  is similar to one previously posted and, since I haven't cracked the analytical solution yet, Car Talk Shootout Version 2 now includes the experimental results for the new problem as well.         

February 27, 2012:  Fifty Probability Problems, Version 5  adds a fifth problem from the book, the hardest one yet, but a good chance to learn about using geometric progressions to solve a puzzle concerning chances for a poor shot to win a  3-way shootout. 

March 6, 2012: "If you draw a 9x9 by nine grid, thus giving yourself 81 small squares;  how many rectangles can you count in total? "   A  little 20 line program, Rectangle Counts, finds the answer and also leads to some interesting math.

 

March 12, 2012:

A solver for a "Special" 5x5 Magic Square was posted today. I call it "Special" because we are given a specific  set of 25 integers from 1 to 9 (with repeats), which must be used to fill the square. The typical 5x5 Magic Square contains integers from 1 to 25 with rows, columns, and diagonals summing to 65.   Each row, column and diagonal in this case must sum to 20.  At left is a typical solution using the given digits 1,1,2,2,2,2,2,3,3,3,3,3,3,4,5,5,5,5,6,6,6,6,6,7,9

A good exercise in Combinatorics and pruning search spaces!  The final version finds  about 5 solutions per second for the first 5000.
March 19, 2012:  I had some fun and learned some things this week writing a Squared Palindromes program which investigates finding  the smallest "even"  palindrome which is the square of another integer. 

March 21, 2012: A small update was posted today to clean up some documentation errors in the description screens of our RSA Keys Demo program.   RSA stands for the last names of the 3 guys that published an algorithm allowing secure message exchange.  In simplest terms,  RSA encryption works like this:

bullet

A wants to be able to receive secure messages from B

bullet

Alice has a key with public and private parts generated using some  well known mathematical magic using random numbers.  She publishes or sends the public part of the key to Bob.  (A and B are always Alice and Bob. J)

bullet

B can encrypt his message using A's public key, using some more agreed upon (and public) math magic. 

bullet

B sends the encrypted message to A (and inadvertently to any eavesdroppers). 

bullet

Using a third bit of math magic which includes her private key, A decrypts B's message and accepts his offer to dinner. 

bullet

The eavesdroppers having A's public key, the encrypted message, and all of the math magic techniques still cannot find out when and where the dinner will take place because they do not know A's private key. 

Interesting stuff!

April 7, 2012: Here is the first (incomplete) version of a Sudoku Helper/Solver. I wrote it on our Caribbean cruise last week while the rest of the family worked on solving the daily puzzles handed out by the cruise line. My way is harder initially, but when they solve one, they have solved one; when I solve one, I have, in theory, solved them all! (That excludes the possibility of program bugs of course, but even those are new and non-repetitive problems to solve one-time. I love it!)

The program allows entering and saving puzzles. As you run across those that cause problems, save and send them on as email attachments to feedback@delphiforfun.org. Pace yourself and only send one per week please (in case the 6 included samples are the only ones the program can solve).

 



To subscribe or unsubscribe from this newsletter, visit http://delphiforfun.org/newsletter.htm

295,000  visitors and 334,000 program downloads in the past 12 months!