Last visit was: It is currently Sat Sep 23, 2023 3:16 pm


All times are UTC-05:00




Post new topic Reply to topic  [2 posts ] 
    Author Message
     Post subject:VDPIN Solver
    PostPosted:Mon Feb 16, 2009 12:50 am 
     

    Joined:Mon Feb 16, 2009 12:42 am
    Posts:11
    The C++ SourceCode:
    #include <iostream>
    #include <memory.h>
    #include <cstdlib>
    #include <typeinfo.h>

    using namespace std;

    #define SIZE 5
    #define ROTATE 3

    template <class T>
    void click(T &data, const int i, const int j, const int count){
    data[j] = (data[j] + count) % ROTATE;
    if (j > 0) data[j - 1] = (data[j - 1] + count) % ROTATE;
    if (j < SIZE - 1) data[j + 1] = (data[j + 1] + count) % ROTATE;
    if (i < SIZE - 1) data[i + 1][j] = (data[i + 1][j] + count) % ROTATE;
    }

    template <class T>
    bool check(T &data){
    for (int i = 1; i < SIZE; i++)
    for (int j = 0; j < SIZE; j++)
    click(data, i, j, ROTATE - data[j]);

    for (int j = 0; j < SIZE; j++)
    if (data[SIZE - 1][j] != 0)
    return false;

    return true;
    }

    int main(){
    int status[SIZE][SIZE];
    int test[SIZE][SIZE];

    for (int i = 0; i < SIZE; i++)
    for (int j = 0; j < SIZE; j++)
    cin>>status[j];

    int searchSum = 1;
    for (int i = 0; i < SIZE; i++) searchSum *= ROTATE;
    int temp;

    for (int i = 0; i < searchSum; i++){
    memcpy(test, status, sizeof(status));
    temp = i;
    for (int j = 0; j < SIZE; j++){
    click(test, 0, j, temp % ROTATE);
    temp /= ROTATE;
    }

    if (check(test)){
    cout<<"The answer is:"<<endl;
    temp = i;
    for (int j = 0; j < SIZE; j++){
    cout<<(temp % ROTATE)<<" ";
    temp /= ROTATE;
    }
    cout<<endl;

    break;
    }
    }

    system("pause");

    return 0;
    }


    Input is a 5 * 5Matrix
    0 Means Blue
    1 Means Green
    2 Means Red
    Such as

    0 1 2 0 0
    1 2 0 0 1
    1 1 1 1 1
    2 2 2 2 2
    0 0 0 0 0

    Output is a 1 * 5Vector, Means the number to click in the first row.
    Such as
    2 1 0 0 0
    Means the top left need to click twice
    then is once

    The rows below first row is related with the row just up them.


    Top
    Offline  
     Post subject:Re: VDPIN Solver
    PostPosted:Mon Feb 16, 2009 4:30 pm 
     

    Joined:Mon Feb 20, 2006 2:48 pm
    Posts:91
    Website:http://master2004134.profusehost.net
    Location:Somewhere on the Net........
    *drool*


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 20 guests


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova