| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

PE011_c

Page history last edited by Kenneth Finnegan 15 years, 7 months ago

#include <stdio.h>

 

// All of this was done with 4 commands in vim

int input[] = {8,2,...,67,48};

 

main() {

    int maxnum = 0;

    int gd[20][20];

    int i, j;

 

     // resort the array into 20x20, and display it

    for (i=0; i<20; i++) {

        for (j=0; j<20; j++) {

            gd[i][j] = input[i*20+j];

            printf("%3d ", gd[i][j]);

        }

        printf("\n");

    }

 

     // Try all 4 directions and keep a running maximum

    for (i=0; i<16; i++) {

        for (j=0; j<16; j++) {

            int temp[4]= {1,1,1,1}, k;

            for(k=0; k<4; k++) {

                temp[0] *= gd[i][j+k]; // right

                temp[1] *= gd[i+k][j]; // down

                temp[2] *= gd[i+k][j+k]; // downright

                temp[3] *= gd[i+4-k][j+k]; // upright

            }

            for(k=0; k<4; k++) {

                if (temp[k] > maxnum) {

                    printf("New solution: %d\n", temp[k]);

                    maxnum = temp[k];

                }

            }

        }

    }

}

Comments (0)

You don't have permission to comment on this page.