Lecture 18, ECE264, Spring 2012, Prof. Lu


John Ribeiro - Lecture 18

A square refers to a single building block the composes a piece. A piece refers to a compilation of multiple squares.

Duplicates are formed through:

Rotation Mirroring

Suppose you want to generate pieces of n squares:

1) Break n into the sum of positive integers. Each integer is the number of squares in each row. 2) Shift the squares to create different pieces 3) Eliminate Duplicates

void f ( int n ) { int i; if ( n == 0 ) {

 return;

} for ( i = 1 ; i < n ; i ++ ) {

 f ( n - i );

} }

That means that each integer can be partitioned into its components, for example,

4 = 1 + 3 4 = 2 + 2 4 = 3 + 1 4 = 4

For each n integer, there will be n partitions

This algorithm will not generate a non-continuous piece

NOT:

xox oxo xox

OR:

oxo oxo ooo

BUT:

ooo oxx ooo

  • Where o denotes a block and x an empty space.


Lecture notes_Lecture18_Mar 20_Kailu Song

1. The explanation of program 2

  a. the square and piece(one piece have several square)
  b. duplicates: rotate the piece will generate another duplicate piece
  c. rotation mirror: horizontal mirror and vertical mirror
  e. invalid piece: there is a space between two square in one row(eg.010 101 010)
  For this assignment, give the number of squares, generate all picecs(delete invalid piece, deplicate piece and mirror piece) using one dimensional array.

2. Hint for this assignment:

  first stage: partition integers:
  ex. 4 = 1+1+1+1
      4 = 1+1+2
      4 = 1+2+1
      4 = 1+3
      4 = 2+2...
  Use recursion
  void f(int n)
  {
    int i;
    if (n==0)
      {
          return;
      }
     if (i=1;i<n;i++)
      {
        f(n-i);
      }
  }
============

Hanye Xu Lec18 Mar 25 Explanation of Ipa2-1 Integer partition use recurstion

void f(int n)
  {
    int i;
    if (n==0)
      {
          return;
      }
     if (i=1;i<n;i++)
      {
        f(n-i);
      }
  }
=====================

Lecture 18 Summery Shiyu Wang Mar25th

This class talked about how to solve IPA2-1. Generally, Tetris usually has 4 squares in each block, in this assignment, we will have different number of squares in each block. And we will print out each combination,which does not includes any duplicates. The duplicates means rotation or mirror. For example,

(111,100)      ,
(100,100,110) are rotation.

(111,100), (111,001), are mirror. All square, need to be connected to each other by side, which means (1000,1100,0110,0011) is valid,but (1000,0100,0010,0001) is not valid. We can solve this problem by splitting the integer in different ways. hint: 5=1+3+1

=2+2+1
=4+1
...

The procedure for solving this problem is, 1. Break n into sum of positive integers, each is number of square in a row. 2. Shift the square to create different species. 3. Eliminate duplicates.

The sample code is like this,

Void f(int n) {

 int i;
 if(n==0)
 {
   print;
   return;
 }
 for(i=0;i<n;i++)
 {
   f(n-1);
 }

}

================================================================

Huayi Guo section-1 Professor Niklas 0321 //Lecture0321 /* ipa2 Generate "super" Blokus Pieces

to take any number of blocks to generate any comfigarition of pieces Not allowed to illimulate rotations ,mirrors and tranlated versions.

stage one: Integer partitions Taking a number and split it into partitions.



  • /

void intpart(int badget, int pos, int *data) {

  int i;

  //Base case;
  if(badget == 0){
     //print postions

return;

  }
  //recursive case:
  for(i = 1; i <= badget; i++){
     data[pos]==i;
     intpart(badget - i, pos+1,data);
  }
  return;

}



===================

Kevin Tan(0023987592), section#2 notes 03/22


three ways to allcate memory

1.static : know the size when writing the program eg. int arr[100]; vector v[200];

2.know the size somewhere during execution eg. int length; scanf("%d",&length); int *arr; arr = malloc(sizeof(int)*(length));

3.grow and shrink based on run-time needs (dynamic structure) eg.linked list binary tree

typedef struct dstruture; {

 int value;
 vector vec;
 person *p;
 
 sturct dstruture *next;
 sturct dstruture *left;
 sturct dstruture *right;

}


===========================

Rohan Khante

============

This class talked about the 2nd IPA. The partition of integers. Partition means breaking a number into other numbers so that the numbers add upto the original number ex

Void f(int n) {

 int i;
 if(n==0)
 {
   printf;
   return;
 }
 for(i=0;i<n;i++)
 {
   f(n-1);
 }

} This functions accepts a number n. n=0 is a special case. For other numbers this is a recursive function. Each partition can be built up from the previous partitions. Example 5 will be outputed as 11111 1112 //series starting with 1s 2111 221 //series starting with 2s 311 32 41 5 Thus the starting number goes from 1 to n. The difference is subtracted from the original number and the partition is done on the REMAINING sum

Professor also discussed the various ways to allocate memory in the program

static: This method is done when one knows the size of a variable when writing the program int array[100] here while writing the program we know that the size of the array will not exceed 100 elements

malloc: this is used when the size of the memory needed will be determined DURING the execution of a program an example case will be if a function returns a certain variable k. This k is going to be the size of the array. NOTE- we do NOT know what the value of K being returned WHILE WRITING the program. we HAVE to use malloc here 2.know the size somewhere during execution //some fuction returns k array = malloc(sizeof(int)*(k)); This will create an array which can hold in k values also do not forget to free the memory once the job is done. You will lose major points if your program has memory leaks. //use array. work with it //once job is done call free free(array);

dynamic structure eg.linked list binary tree This method is used when the size of memory needed will change during the program. Can increase or decrease during the execution NOTE- this is different from the previous case. LOOSELY the difference can be said that "n" will change during the program example= the number of users on Facebook Facebook stores a large number of data for each user. Their names age etc For storing names one can use malloc But for storing personal profiles as a whole one has to use lists/trees This is because the profiles keep changing constantly. A person may delete his profile or new profiles maybe created.


Back to ECE264, Spring 2012, Prof. Lu

Alumni Liaison

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood