Mathematica Pearls

Problems and Solutions					Vol 8  No 1

by Don Piele

Welcome back to Mathematica Pearls, the column devoted to examining interesting Mathematica solutions to an assortment of simple and appealing problems. 

In the70's and 80's, programming in BASIC or Pascal was a common activity for students taking computer classes in school. In the early days of the PC, all of the computer magazines and books contained program listings inviting the reader to enter and run them. I still have a copy of "What To Do After You Hit Return or P.C.C.'s First Book of Computer Games" by People's Computer Company. It is filled with BASIC code written to play number guessing games, word games, "Nimlike" games, pattern games, and board games. Many of us learned programming by taking the code apart to see what made it tick. Unlike the traditional school mathematics problem, the way people chose to solve the same programming problem was typically very different and very original.

As a result of this new problem solving paradigm, young minds dove full speed into programming and became exceedingly good at it.  In all other school subjects the same students were never a threat. But when it came to computer programming the tables were reversed. It is hard to think of another school subject where this has ever happened. 

In 1981, I organized the first National Computer Problem Solving Competition and ran it in Creative Computing magazine. The goal was to create a standardized set of computer programming problems to challenge the BASIC language abilities of primary and secondary students. There were three divisions; Elementary (grades 4-6), Junior (grades 7-9) and Senior (grades 10-12).The following year it became the International Computer Problem Solving Contest (ICPSC). It grew in popularity along with the push to introduce computer programming in the schools. It peaked in the late 80's when schools shifted from offering programming courses to teaching computer literacy. In 1993, it was replaced by the USA Computing Olympiad that selects the USA programming team to the annual International Olympiad in Informatics (www.usaco.org). What once involved over 5,000 students with a wide range of abilities and ages, now focused on the top 200 high school students, mostly Juniors and Seniors, who are actively engaged in advanced programming courses high school.

So what does this all have to do with Mathematica Pearls? Simple. I though it would be fun and educational to see how the readers of this magazine would use Mathematica go about solving a sample set of the same problems that appeared in the ICPSC.   Let's call it Pearl Harvest I.

Pearl Harvest I

Goals
1) Help beginners.
Pearl Harvest I provides a common set of  programming problems to work on. You may not find the best solution, but can you find any solution? In the process of trying to solve these problems, you stand the most to gain.
   
 2) Find the best solution.
 The best solution will most likely be found by experienced Mathematica users.   An explanation of the best solutions will help everyone advance in their Mathematica programming skills.
 
3) Encourage and support programming in Mathematica.
 Mathematica is a relatively new programming language that needs encouragement at the beginning level.  The best way to learn how to advance your skill is to work on problems. Our fine community of advanced users is always willing to share their ideas. 

Email your solutions to don@piele.com.  All Mathematica solutions, especially from beginners,  are welcome. A variety of solutions will be presented in Mathematica Pearls in Vol 8 No. 3.  Have fun!

Unique Quotients ('92)

Create the function uniqueQuotients[n_] that finds all solutions to the expression:

						(ABCDE/(FGH I J ))== n 
						
where A,B,C,D,E,F,G,H,I,J  are unique digits ( 0 through 9) that appear once and only once. Leading zeros are allowed, i.e.,  F can be zero.

One solution for n= 9,   ABCDEFGHIJ = 5742906381

Zero Sum ('89)

Create the function zeroSum[n_] that finds all solutions to the expression:

	                         	1 @ 2 @ 3 @......@n == 0 
	                         	
where n is a single digit and each occurance of @ can be either a (+) or (-) or () which means to concatenate the digits.

One solution for n = 7,  1 - 23 - 45 + 67

Latin Squares ('83)

Create the function latinSquares[n_] that finds all n x n Latin Squares for n<=9. A square matrix of the form

						 ({{1, 2, 3, 4, 5}, {2, 1, 4, 5, 3}, {3, 4, 5, 1, 2}, {4, 5, 2, 3, 1}, {5, 3, 1, 2, 4}})
						
is a 5 x 5 Latin Square. Note that each digit appears once and only once in each row and column. Since any permuation of the columns is a solution, find only the solutions where the first row is the digits 1 2 3 ... n. 

One solution for n = 5 is shown above.

About The Author

Don Piele has been interested in creating programming problems since he began the International Computer Problem Solving Contest in the pages of Creative Computing in 1981. In 1992, he organized the USA Computing Olympiad (USACO),  which selects the top four American high school computer programmers to represent the USA at the annual International Computing Olympiad. He also writes a column, "Cowculations," in Quantum Magazine , devoted to computer algorithms using Mathematica. The Web address for the USACO is: http:// www.usaco.org.

Don Piele
Mathematics Department
University of Wisconsin-Parkside
Kenosha, WI 53141
don@piele.com