Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:46:45+00:00 2026-06-14T22:46:45+00:00

I have this Matrix: A B C D E F G H I I

  • 0

I have this Matrix:

A B C

D E F

G H I

I want to get all possible combinations of adjacent cells and diagonal cells with a lenght of 3, for example:

Starting from A:

 - *ABC* right right
 - *ABE* right down
 - *ABF* right diagonal-right
 - *ABD* right diagonal-left
 - ecc ecc

I tried to create a new class called “lettera”, with as key the letter, and with a member that indicates the pointer to right, left, down, up ecc. And also with a member called “sequenza”, a string that concatenate every letter it touch.

For example if a have as key, “B”, i have B->down == *E, B->left == *A, B->right == *C and so on…
And it works. Then I put a counter for each letter: when it arrives at 3 it should stop determinating combinations.

Then the core of the problem: the path for each letter to follow… I tried do create a recursive function, but it doenst work.

Can you please help me by watching this or by suggesting me another way?

Thanks a lot.

The code:

    void decisione(lettera *c) {

            if (c == nullptr) return ;

            c->count++;
            c->sequenza = c->sequenza + c->key;

            if (c->count == 2) 
                    cout << "\n" << c->sequenza; 
                 //the sequence of letters accumulated in every call
            decisione(c->Up);
            decisione(c->Down);

        }

It gives me for example AAA and BBB and then it crashes =(

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:46:46+00:00Added an answer on June 14, 2026 at 10:46 pm

    Start at A, where can you go? B and D. Suppose you go to B, now, where can you go? A, C and E. You’ve already been in A and you don’t want to return, so you only have C and E. Suppose you pick C, as you have already picked three letters the function stops and then you pick E and so on (I’m not choosing diagonal neighbors), here is the program:

    #include <cstdio>
    #include <cstdlib>
    
    int a[] = {-1,-1,-1,0,0,1,1,1}, b[] = {-1,0,1,-1,1,-1,0,1},cont;
    char s[3],mat[3][3];
    bool flag[9];
    
    void display() {
      for(int i = 0; i < 3; ++i) printf("%c",s[i]);
      puts("");
    }
    
    void show(int x,int y) {//You are in mat[x][y]
      s[cont] = mat[x][y];
      if(cont == 2) {
        display();
        return;
      }
      flag[mat[x][y] - 'A'] = true;
      int xx,yy;
      for(int i = 0; i < 8; ++i) {
        xx = x + a[i], yy = y + b[i];
        if(0 <= xx and xx < 3 and 0 <= yy and yy < 3 and !flag[mat[xx][yy] - 'A']) {
          ++cont;
          show(xx,yy);
          --cont;
        }
      }
      flag[mat[x][y] - 'A'] = false;
    
    }
    
    int main() {
      cont = 0;
      for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
          mat[i][j] = ('A' + 3*i + j);
        }
      }
      for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
          show(i,j); //You start from mat[i][j]: {'A','B','C',...,'I'}
        }
      }
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this matrix of size 10000 by 1. I want to remove some
so we have this matrix a=[1;2;3] and we want to multiply it by itself
I have this following numpy matrix that I want to sort in ascending order
I want to read the pixels from the back buffer. But all i get
This is an easy question but say I have an MxN matrix. All I
I have a string like this: matrix(10, 0, 1, 0, -198, 23) Then I
I have a matrix and I need to find a pattern inside this matrix.
Supose I have a matrix. This matrix is blank except some points that create
If I have this: A * f = g; A: upper triangular matrix (n
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.