# Thread: symmetryc problem

1. ## symmetryc problem

I'm doing a program in c, where I need to read a file, place it in an array and compare the vertical and horizontal symmetry about ASCII symbols.

The input file contains a figure created
on the basis of any ASCII characters.
For example, the first figure shown in this document:
* *
* * * *
* * * *
* * * * * * Vertical

+ + + + + + + +
+ + + + + + +
+ + + +
+ + + + + + +
+ + + + + + + + Horizontal
would be represented in this file follows:
The program will analyze the figure, detecting all possible
symmetries that sample, and generating an output file with
Detailed information on all the symmetries detected. The
information generated in each case is as follows.

Yo I have done the following:

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "funcions.h"

int main(int argc, char** argv)
{

FILE *f1;
int **matriu;
int test=0;
int N;
int i=0;
int M;
char c;

if ((f1=fopen("ejemplo.c","r")) == NULL)  // obre l'arxiu
{
printf("No s'ha trobat cap fitxer anomenat així");
}

else
{
int N;
int i;
int j;

fscanf(f1,"%d",&N);
fscanf(f1,"%d",&M);

matriu=(int**) malloc((N*M*sizeof(int*)));	//reserva l'espai necessari per la matriu

for(i=0; i<N; i++)
{
for (j=0;j<M;j++)
matriu[i]=(int*) malloc((N*sizeof(int)));
}

fLectura(matriu,f1,N);
fEscriure(matriu,f1,N);	//llegeix el fitxer i coloca els valors al lloc corresponent de la matriu
//Aqui haura de comparar les files i columnes, i la suma de asteriscos per veure si es reursiva
}

// En aquesta part obrin l'arxiu i creem la matriu.

void fLectura(int **matriu,FILE *f1,int N)
{
int a,b,z;
for (a=0; a<N; a++)
{
for (b=0; b<N; b++)
{
fscanf(f1,"%d",&z);
matriu[a][b]=z;
//printf("matriu[%d][%d]: %d \n", a,b,matriu[a][b]);
}
}
}

void fEscriure(int **matriu,FILE *f1, int N)
{
int a,b;
fprintf(f1 ,"%d ", N);
for (a=0; a<N; a++)
{
for (b=0; b<N; b++)
{
printf("matriu[%d][%d]: %d \n", a,b,matriu[a][b]);
fprintf(f1 ,"%d ", matriu[a][b]);
}
}
}```

2. So, what's got you stumped, specifically?

I don't want to play detective with your program, sorry.

3. I've been trying to do the function, to view
symmetry, but can not get me out ... took about
few days of trying and no way

4. Show the output you want, from an input file (exactly), and attach the input file.

To attach a file, go down the editor page, and click on the "manage attachments" button, and upload the file. The "Attachments" pull down menu at the top of the editor window, doesn't work, AFAIK.

5. I was on the post what I have done, the input into and
the output would like.

6. In the output file:
Code:
```*     *
**   **
**   **
*** ***
simettry: form
orientation: vertical/horizontal
Size of array: 4 4
Character: *
character times: 8```
I'm unclear about symmetry: form.

Can you explain that?

7. symetry: form because there are another symmetry of content, but i don't upload this part of work

8. Program to make
There must be a program by the command line take name of an input text file, and also name 1
Note that in this type of symmetry, the type of character does not matter. That is, all different characters are white space treated equally. output file. The input file will contain a figure created on the basis of any ASCII characters.
For example, the first figure shown in this document:
Code:
```*          *
* *      * *
* *      * *
* * *  * * *```
would be represented in the file of the following form:
The program will analyze the figure, detecting all possible symmetries that sample, and generating an output file with detailed information on all the symmetries detected.
The information generated in each case is as follows.
Output for Shape Symmetry
The output file should contain:
1. Repetition of the original figure in its entirety
2. Type of symmetry: a
3. Orientation: vertical or horizontal.
4. What is the size of each half has been divided figure
5. What is the ASCII character has been predominant used for create the figure. It should be noted that a figure can have symmetry of form, despite using more than one character ASCII
implementation. If more than one ASCII character appear the same number of times, can be indicated either them (Only one would suffice)
6. What is the number of occurrences of this character in each half of the figure In the example shown at the beginning of this section, output should include exactly (same order, words, punctuation, uppercase and lowercase letters, without accents, etc..), the following
content:

Code:
```*          *
* *      * *
* *      * *
* * *  * * *```
It should be noted that it is possible that the same figure shows both vertical and horizontal symmetry. In this case, you leave one blank line, and then show (repeat) all information
detailed here for each of the cases, except made of reproduce the original figure, it is only necessary show once All output file.
In the event that the figure is not symmetrical, the file output should contain only a reproduction of it, and more line stating: "Symmetry: no." Nothing more. Output for Symmetry Content Suppose we want to represent in the file following figure:

Code:
```* *   * * *
* *     * +
* *      *
* *       *
*   + * * *
* * * *```
Which has horizontal symmetry of contents:

Program to make
There must be a program by the command line take name of an input text file, and also name 1
Note that in this type of symmetry, the type of character does not matter. That is, all different characters are white space treated equally. output file. The input file will contain a figure created on the basis of any ASCII characters.
For example, the first figure shown in this document:
Code:
```*          *
* *      * *
* *      * *
* * *  * * *```
would be represented in the file of the following form:
The program will analyze the figure, detecting all possible symmetries that sample, and generating an output file with detailed information on all the symmetries detected.
The information generated in each case is as follows.
Output for Shape Symmetry
The output file should contain:
1. Repetition of the original figure in its entirety
2. Type of symmetry: a
3. Orientation: vertical or horizontal.
4. What is the size of each half has been divided figure
5. What is the ASCII character has been predominant used for create the figure. It should be noted that a figure can have symmetry of form, despite using more than one character ASCII
implementation. If more than one ASCII character appear the same number of times, can be indicated either them (Only one would suffice)
6. What is the number of occurrences of this character in each half of the figure In the example shown at the beginning of this section, output should include exactly (same order, words, punctuation, uppercase and lowercase letters, without accents, etc..), the following
content:

Code:
```*          *
* *      * *
* *      * *
* * *  * * *```
It should be noted that it is possible that the same figure shows both vertical and horizontal symmetry. In this case, you leave one blank line, and then show (repeat) all information
detailed here for each of the cases, except made of reproduce the original figure, it is only necessary show once All output file.
In the event that the figure is not symmetrical, the file output should contain only a reproduction of it, and more line stating: "Symmetry: no." Nothing more. Output for Symmetry Content Suppose we want to represent in the file following figure:

Code:
```* *   * * * 5
* *     * +  4
* *      *   3
* *       *    3
*   + * * * 5
* * * *    4```
as their 'vectors of values' are, respectively, <5,4,3> and <3,5,4>. These vectors are the same, but with management different.
Code:
```*          *
* *      * *
* *      * *
* * *  * * *
Symmetry: shape
Orientation: Vertical
Tamani: April 4
Character: *
Appearances: 8```
The input file is as follows:
Code:
```* *   * * *
* *     * +
* *      *
* *       *
*   + * * *
* * * *```
The output file should contain:
1. Repetition of the original figure in its entirety
2. Type of symmetry: content
3. Orientation: vertical or horizontal.
4. What is the size of each half has been divided figure
5. What is the ASCII character has been predominant
used for create the figure. If more than one ASCII character appear the same number of times it can be mentioned any of them (only one would suffice)
6. What is the number of occurrences of this character in each half of the figure
7. The 'vector of values' sorted descending
8. Figure Play 'equivalent to the original' that sample symmetry of form
In the example in this section, the output would following:
Code:
```* *   * * *
* *     * +
* *      *
* *       *
*   + * * *
* * * *

Symmetry: content
Orientation: horizontal
S size: 3 6
Character: *
Appearances: 12
Values: 5 4 3
*****
****
***
***
****
*****```
It should be noted that it is possible that the same figure shows both vertical and horizontal symmetry. In this case, you leave one blank line, and then show (repeat) all information detailed here for each of the cases, except made of reproduce the original figure, it is only necessary show once all output file.

9. I don't read whatever language that is in the program. What did the instructor want to see you use for an algorithm?

I'll be off the forum for several hours now, but will get back to you.

10. The instructor wants me to do a program where from a text file with ASCII elements, say if either side is symmetric, setting ASCII house in a position of the matrix array divided by the center, horizontally or vertically, to see if either side is symmetrical, so I'm not out is the comparison, I need a function to do this.

11. Originally Posted by raizard
The instructor wants me to do a program where from a text file with ASCII elements, say if either side is symmetric, setting ASCII house in a position of the matrix array divided by the center, horizontally or vertically, to see if either side is symmetrical, so I'm not out is the comparison, I need a function to do this.
OK, i understand. I know how I would do it, but I thought the instructor might have told you how he wanted to have you do it.

My idea is to make another matrix, equal in dimension to half the original. Then transpose the upper half of the original (for example), into the new matrix.

Then in a for loop, scan through the new array and the lower half of the original array, and see if there are any differences. If one element has a different value in that comparison, then the symmetry is broken for that transposition (say horizontal for this example).

Now repeat it with a zero'd out new matrix, for the vertical symmetry test, transposing the left hand side of the matrix, into the new matrix, and then comparing it with the right half of the original matrix. Again, using a for loop.

Sound right to you?

There may be a slick way to do this with just offsets - let me ponder that one.

Ah! Catalan! - I was thinking "Close to Spanish but no, maybe Portuguese - but nope. What language IS this?

12. yes, my instructor want to i do it, but i'm trying but i can't do...

This is my code but it fail...
I need it for tomorrow...

Code:
```#include <stdio.h>
#include <string.h>
#define N 3
#define M 4
main()

{
char c='*',d='+';

int f[N][M] = {{d,d,d,c},{c,c,c,c},{c,d,d,c}};
int x;
int y=0;
int cont=1;;

for (y=0;y<M;y++)
{
while (x<=((N/2)-1) && cont<=(N/2))
{
if ((f[x][y])!=(f[N-cont][y]))
{
printf("No te simetria vertical");
}
cont++;
x++;
}
}
printf("Te simetria vertical");

cont=1;
y=0;

for (x=0;x<N;x++)
{
while (y<=((M/2)-1) && cont<=(M/2))
{
if ((f[x][y])!=(f[x][M-cont]))
{
printf("No te simetria horitzontal");
}
cont++;
y++;
}
}

printf("Te simetria horitzontal");

cont=1;
x=0;

}```

13. The horizontal fails us when the matrix is 4x4, 6x6 and works with 3x3, 5x5 ...
The vertical Always Fails ....

14. This is your program, with a few tweaks. For both horizontal and vertical symmetry, it works ONLY from the center of the array. That's what I interpret symmetry to mean.

Post back if you find a bug here. I didn't test it much due to time constraints.

Code:
```/* tests for symmetry in horizontal or vertical mode, of an array

Status: needs testing

*/

#include <stdio.h>
#include <string.h>
#define N 4
#define M 4
#define d '+'
#define c '*'

#pragma warn -rch

int main() {
int bad, i, j, row, col, mid;	/* i counts forward, j counts backward */
int f[N][M] = {
{c,c,c,c},
{c,c,c,d},
{c,c,c,d},
{c,c,c,c}};
//  {c,c,c,c}};
printf("\n\n");
/* show the f array */
for(row=0;row<N;row++) {
for(col=0;col<M;col++) {
printf("%c ", f[row][col]);
}
putchar('\n');
}
printf("\n\n");
/* begin horizontal symmetry test */
if(N%2==1) {
mid = N/2;
j=N-1;
for(row=0;row<mid;row++) {
for(col=0;col<M;col++) {
if(f[row][col] != f[j][col]) {
break;
}
}
break;
else
--j;
}
}
else {  //N is even
mid=N/2;
j=N-1;
for(row=0;row<mid;row++) {
for(col=0;col<M;col++) {
if(f[row][col] != f[j][col]) {
break;
}
}
break;
else
--j;
}
}
printf("\n no horizonatal symmetry was found");
else
printf("\n horizontal symmetry was found");

/* begin vertical symmetry testing */
if(M%2==1) {  /* has odd number of columns */
mid=M/2;
j=mid+1;

for(row=0;row<N;row++) {
for(col=0;col<mid;col++) {
if(f[row][col] != f[row][col+j]) {
break;
}
}
break;
}
}
else {  //M is even
mid=M/2;
j=mid;
for(row=0;row<N;row++) {
for(col=0;col<mid;col++) {
if(f[row][col] != f[row][col+j]) {
break;
}
}
break;
}
}