K
K
Konstantin2018-07-01 17:20:56
C++ / C#
Konstantin, 2018-07-01 17:20:56

What is the formula for the exhaustive search of two ranges algorithm?

Hello eagles! Help someone who fumbles in algorithms.
We need an algorithm to enumerate two ranges, for example, all options from the range a (1-10) to the range b (15-30) I started doing it myself, but I missed something in the code.

spoiler
void comb2(int a, int b, int c, int d) // a,b,c,d - границы первого и второго диапазонов
{
  for (int i = a; i < b; i++) // перебор первого диапазона
  {	for (int j = a; j < b; j++)
    cout << char(i) << char(j) << "\n";		}

  for (int i = c; i < d; i++) // перебор второго диапазона
  {	for (int j = c; j < d; j++)
    cout << char(i) << char(j) << "\n";		}

  for (int i = a; i < b; i++) // скрещенный перебор диапазонов
  {	for (int j = c; j < d; j++)
    cout << char(i) << char(j) << "\n";		}

  for (int i = c; i < d; i++) // перевернутый скрещенный перебор диапазонов
  {	for (int j = a; j < b; j++)
    cout << char(i) << char(j) << "\n";		}
}

Thanks for any help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-07-01
@MKaffein

cartesian product c

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question