Project 2

Last revision:  January 27 1999

Author: YourNameGoesHere

Lots of Lists

General suggestions:

(a) Make sure you know how to do a simple example by hand.

(b) With scratch work (not on computer), develop an algorithm (or method) which has steps you think Mathematica can accomplish.  Think in terms of rows (or entire lists).

(c) Use bottom-up analysis, defining and testing functions as you build up parts of the programming task.

Part A:  Individually Pledged

If you choose to do Part B with a partner, turn Part A in separately, with the pledge written out in the notebook if submitted electronically.

1. Write a function "combineFactors" which performs the opposite of the Mathematica function "FactorInteger".  For example, 1500=(2^2)*3*(5^3), so "FactorInteger[1500]" returns "{{2,2},{3,1},{5,3}}"; similarly, "combineFactors[{{2,2},{3,1},{5,3}}]" should return the Integer 1500.

2. Recall that Pascal's Triangle looks like this:
     1
    1 1
   1 2 1
  1 3 3 1
 and so on; each row is one longer than the one before, and successive entries (except the 1's on the end) are given by consecutive sums of entries on the preceding row.
  
Write a function "pascal[ ]" which has as its argument an Integer indicating how many rows the user would like and outputs that many rows of Pascal's Triangle.  

For example, "pascal[4]" would produce the (nested) list "{{1}, {1,1}, {1,2,1}, {1,3,3,1}}".

Generate the triangle by addition; do not use the function "Binomial[ ]".

Part B:  Individually Pledged OR Pledged with One Partner

If you choose to do Part B with a partner, turn in Part B separately with the pledge for both partners written out in the notebook.

3.  A permutation of length "n" is a list of the first n positive integers in some order.  Example:  {6,1,5,3,4,2} is a permutation of length 6.  A permutation is called balanced if the sum of each consecutive pair is equal to the sum of the consecutive pair furthest away from the original pair, if we imagine the permutation written in a circle.  For instance, (6,1) and (3,4) are pairs furthest away in the example above, because they are both 1 unit away from the original pair.  Similarly, (2,6) and (5,3) are furthest apart.  Our example is balanced because pairs furthest apart have the same sum: 6+1=3+4; 1+5 =4+2; 5+3=2+6; 3+4=6+1; 4+2=1+5; 2+6=5+3.  Another way to see this is to write the consecutive sums in order (7,6,8,7,6,8) and notice that the corresponding sums are the furthest apart.  Note that all of this makes sense only if the length of the permutation (n) is even.

(a) Write a function "balancedQ[ ]" which takes one argument which is a list of even length and returns True if it is balanced, False otherwise.

(b) The Mathematica function "Permutations[]" returns all possible permutations of the elements of a list.  Use "Permutations[]" and your function "balancedQ[]" to find all balanced permutations of the numbers {1,2,3,4,5,6}.