# Print all combinations of n natural number whose pair element difference is one

Here given code implementation process.

// C Program
// Print all combinations of n natural number
// whose pair element difference is one
#include <stdio.h>

void subSequences(int result[], int start, int count, int n)
{
if (count == n)
{
// Display resultant sequence
for (int i = 0; i < n - 1; i += 2)
{
printf("(%d,%d) ", result[i], result[i + 1]);
}
printf("\n");
}
else if (count > n)
{
return;
}
else
{
for (int i = start; i < n; i += 2)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
subSequences(result, start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
subSequences(result, i, count + 2, n);
}
}
}
void pairDifferences1s(int n)
{
if (n % 2 != 0)
{
printf("\n Given n : %d is not even \n", n);
}
if (n <= 0)
{
return;
}
printf(" Given : %d \n",n);
// Auxiliary array which is collect result
int result[n];
subSequences(result, 0, 0, n);
}
int main()
{
//  Length and natural number 1..n
int n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
pairDifferences1s(n);
n = 6;
/*

n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
pairDifferences1s(n);
return 0;
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
// Java program for
// Print all combinations of n natural number
// whose pair element difference is one
public class Combination
{
public void subSequences(int[] result,
int start, int count, int n)
{
if (count == n)
{
// Display resultant sequence
for (int i = 0; i < n - 1; i += 2)
{
System.out.print("(" + result[i] +
"," + result[i + 1] + ") ");
}
System.out.print("\n");
}
else if (count > n)
{
return;
}
else
{
for (int i = start; i < n; i += 2)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
subSequences(result, start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
subSequences(result, i, count + 2, n);
}
}
}
public void pairDifferences1s(int n)
{
if (n % 2 != 0)
{
System.out.print("\n Given n : " +
n + " is not even \n");
}
if (n <= 0)
{
return;
}
System.out.print(" Given : " + n + " \n");
// Auxiliary array which is collect result
int[] result = new int[n];
subSequences(result, 0, 0, n);
}
public static void main(String[] args)
{
//  Length and natural number 1..n
int n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*

n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
#include <iostream>

using namespace std;
// C++ program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination
{
public: void subSequences(int result[],
int start,
int count,
int n)
{
if (count == n)
{
// Display resultant sequence
for (int i = 0; i < n - 1; i += 2)
{
cout << "("
<< result[i]
<< ","
<< result[i + 1]
<< ") ";
}
cout << "\n";
}
else if (count > n)
{
return;
}
else
{
for (int i = start; i < n; i += 2)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
this->subSequences(result, start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
this->subSequences(result, i, count + 2, n);
}
}
}
void pairDifferences1s(int n)
{
if (n % 2 != 0)
{
cout << "\n Given n : " << n << " is not even \n";
}
if (n <= 0)
{
return;
}
cout << " Given : " << n << " \n";
// Auxiliary array which is collect result
int result[n];
this->subSequences(result, 0, 0, n);
}
};
int main()
{
//  Length and natural number 1..n
int n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*

n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
return 0;
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
// Include namespace system
using System;
// Csharp program for
// Print all combinations of n natural number
// whose pair element difference is one
public class Combination
{
public void subSequences(int[] result,
int start, int count, int n)
{
if (count == n)
{
// Display resultant sequence
for (int i = 0; i < n - 1; i += 2)
{
Console.Write("(" + result[i] + "," +
result[i + 1] + ") ");
}
Console.Write("\n");
}
else if (count > n)
{
return;
}
else
{
for (int i = start; i < n; i += 2)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
this.subSequences(result,
start + 2,
count + 2,
n);
result[count] = i + 2;
result[count + 1] = i + 1;
this.subSequences(result,
i,
count + 2,
n);
}
}
}
public void pairDifferences1s(int n)
{
if (n % 2 != 0)
{
Console.Write("\n Given n : " +
n + " is not even \n");
}
if (n <= 0)
{
return;
}
Console.Write(" Given : " + n + " \n");
// Auxiliary array which is collect result
int[] result = new int[n];
this.subSequences(result, 0, 0, n);
}
public static void Main(String[] args)
{
//  Length and natural number 1..n
int n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
package main
import "fmt"
// Go program for
// Print all combinations of n natural number
// whose pair element difference is one
type Combination struct {}
func getCombination() * Combination {
var me *Combination = &Combination {}
return me
}
func(this Combination) subSequences(result[] int,
start int,
count int,
n int) {
if count == n {
// Display resultant sequence
for i := 0 ; i < n - 1 ; i += 2 {
fmt.Print("(",
result[i],
",",
result[i+1],
") ")
}
fmt.Print("\n")
} else if count > n {
return
} else {
for i := start ; i < n ; i += 2 {
// Set pair element
result[count] = i + 1
result[count + 1] = i + 2
this.subSequences(result, start + 2, count + 2, n)
result[count] = i + 2
result[count + 1] = i + 1
this.subSequences(result, i, count + 2, n)
}
}
}
func(this Combination) pairDifferences1s(n int) {
if n % 2 != 0 {
fmt.Print("\n Given n : ", n, " is not even \n")
}
if n <= 0 {
return
}
fmt.Print(" Given : ", n, " \n")
// Auxiliary array which is collect result
var result = make([] int, n)
this.subSequences(result, 0, 0, n)
}
func main() {
var task * Combination = getCombination()
//  Length and natural number 1..n
var n int = 4
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
<?php
// Php program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination
{
public	function subSequences(\$result,
\$start,
\$count,
\$n)
{
if (\$count == \$n)
{
// Display resultant sequence
for (\$i = 0; \$i < \$n - 1; \$i += 2)
{
echo("(".\$result[\$i].
",".\$result[\$i + 1].
") ");
}
echo("\n");
}
else if (\$count > \$n)
{
return;
}
else
{
for (\$i = \$start; \$i < \$n; \$i += 2)
{
// Set pair element
\$result[\$count] = \$i + 1;
\$result[\$count + 1] = \$i + 2;
\$this->subSequences(\$result,
\$start + 2,
\$count + 2,
\$n);
\$result[\$count] = \$i + 2;
\$result[\$count + 1] = \$i + 1;
\$this->subSequences(\$result,
\$i,
\$count + 2,
\$n);
}
}
}
public	function pairDifferences1s(\$n)
{
if (\$n % 2 != 0)
{
echo("\n Given n : ".\$n.
" is not even \n");
}
if (\$n <= 0)
{
return;
}
echo(" Given : ".\$n.
" \n");
// Auxiliary array which is collect result
\$result = array_fill(0, \$n, 0);
\$this->subSequences(\$result, 0, 0, \$n);
}
}

function main()
{
//  Length and natural number 1..n
\$n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
\$n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
main();

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
// Node JS program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination
{
subSequences(result, start, count, n)
{
if (count == n)
{
// Display resultant sequence
for (var i = 0; i < n - 1; i += 2)
{
process.stdout.write("(" +
result[i] + "," +
result[i + 1] + ") ");
}
process.stdout.write("\n");
}
else if (count > n)
{
return;
}
else
{
for (var i = start; i < n; i += 2)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
this.subSequences(result,
start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
this.subSequences(result,
i, count + 2, n);
}
}
}
pairDifferences1s(n)
{
if (n % 2 != 0)
{
process.stdout.write("\n Given n : " +
n + " is not even \n");
}
if (n <= 0)
{
return;
}
process.stdout.write(" Given : " + n + " \n");
// Auxiliary array which is collect result
var result = Array(n).fill(0);
this.subSequences(result, 0, 0, n);
}
}

function main()
{
//  Length and natural number 1..n
var n = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
main();

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
#  Python 3 program for
#  Print all combinations of n natural number
#  whose pair element difference is one
class Combination :
def subSequences(self, result, start, count, n) :
if (count == n) :
i = 0
#  Display resultant sequence
while (i < n - 1) :
print("(",
result[i] ,",",
result[i + 1] ,") ",
end = "",sep = "")
i += 2

print(end = "\n")
elif (count > n) :
return
else :
i = start
while (i < n) :
#  Set pair element
result[count] = i + 1
result[count + 1] = i + 2
self.subSequences(result,
start + 2,
count + 2,
n)
result[count] = i + 2
result[count + 1] = i + 1
self.subSequences(result,
i,
count + 2,
n)
i += 2

def pairDifferences1s(self, n) :
if (n % 2 != 0) :
print("\n Given n : ", n ," is not even ")

if (n <= 0) :
return

print(" Given : ", n ," ")
#  Auxiliary list which is collect result
result = [0] * (n)
self.subSequences(result, 0, 0, n)

def main() :
#   Length and natural number 1..n
n = 4
#    n = 4
#    ----------
#    (1,2) (3,4)
#    (1,2) (4,3)
#    (2,1) (1,2)
#    (2,1) (2,1)
#    (2,1) (3,4)
#    (2,1) (4,3)
#    (3,4) (3,4)
#    (3,4) (4,3)
#    (4,3) (3,4)
#    (4,3) (4,3)
#  Test A
n = 6
#    n = 6
#    pair n/2 = 3 pair in each result
#    ----------
#    (1,2) (3,4) (5,6)
#    (1,2) (3,4) (6,5)
#    (1,2) (4,3) (3,4)
#    (1,2) (4,3) (4,3)
#    (1,2) (4,3) (5,6)
#    (1,2) (4,3) (6,5)
#    (1,2) (5,6) (5,6)
#    (1,2) (5,6) (6,5)
#    (1,2) (6,5) (5,6)
#    (1,2) (6,5) (6,5)
#    (2,1) (1,2) (3,4)
#    (2,1) (1,2) (4,3)
#    (2,1) (1,2) (5,6)
#    (2,1) (1,2) (6,5)
#    (2,1) (2,1) (1,2)
#    (2,1) (2,1) (2,1)
#    (2,1) (2,1) (3,4)
#    (2,1) (2,1) (4,3)
#    (2,1) (2,1) (5,6)
#    (2,1) (2,1) (6,5)
#    (2,1) (3,4) (3,4)
#    (2,1) (3,4) (4,3)
#    (2,1) (3,4) (5,6)
#    (2,1) (3,4) (6,5)
#    (2,1) (4,3) (3,4)
#    (2,1) (4,3) (4,3)
#    (2,1) (4,3) (5,6)
#    (2,1) (4,3) (6,5)
#    (2,1) (5,6) (3,4)
#    (2,1) (5,6) (4,3)
#    (2,1) (5,6) (5,6)
#    (2,1) (5,6) (6,5)
#    (2,1) (6,5) (5,6)
#    (2,1) (6,5) (6,5)
#    (3,4) (3,4) (5,6)
#    (3,4) (3,4) (6,5)
#    (3,4) (4,3) (3,4)
#    (3,4) (4,3) (4,3)
#    (3,4) (4,3) (5,6)
#    (3,4) (4,3) (6,5)
#    (3,4) (5,6) (5,6)
#    (3,4) (5,6) (6,5)
#    (3,4) (6,5) (5,6)
#    (3,4) (6,5) (6,5)
#    (4,3) (3,4) (5,6)
#    (4,3) (3,4) (6,5)
#    (4,3) (4,3) (3,4)
#    (4,3) (4,3) (4,3)
#    (4,3) (4,3) (5,6)
#    (4,3) (4,3) (6,5)
#    (4,3) (5,6) (5,6)
#    (4,3) (5,6) (6,5)
#    (4,3) (6,5) (5,6)
#    (4,3) (6,5) (6,5)
#    (5,6) (3,4) (5,6)
#    (5,6) (3,4) (6,5)
#    (5,6) (4,3) (3,4)
#    (5,6) (4,3) (4,3)
#    (5,6) (4,3) (5,6)
#    (5,6) (4,3) (6,5)
#    (5,6) (5,6) (5,6)
#    (5,6) (5,6) (6,5)
#    (5,6) (6,5) (5,6)
#    (5,6) (6,5) (6,5)
#    (6,5) (6,5) (5,6)
#    (6,5) (6,5) (6,5)
#  Test B

if __name__ == "__main__": main()

#### Output

Given :  4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given :  6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
#  Ruby program for
#  Print all combinations of n natural number
#  whose pair element difference is one
class Combination
def subSequences(result, start, count, n)
if (count == n)
i = 0
#  Display resultant sequence
while (i < n - 1)
print("(", result[i] ,",",
result[i + 1] ,") ")
i += 2
end

print("\n")
elsif (count > n)
return
else

i = start
while (i < n)
#  Set pair element
result[count] = i + 1
result[count + 1] = i + 2
self.subSequences(result,
start + 2,
count + 2, n)
result[count] = i + 2
result[count + 1] = i + 1
self.subSequences(result,
i,
count + 2,
n)
i += 2
end

end

end

def pairDifferences1s(n)
if (n % 2 != 0)
print("\n Given n : ",
n ," is not even \n")
end

if (n <= 0)
return
end

print(" Given : ", n ," \n")
#  Auxiliary array which is collect result
result = Array.new(n) {0}
self.subSequences(result, 0, 0, n)
end

end

def main()
#   Length and natural number 1..n
n = 4
#    n = 4
#    ----------
#    (1,2) (3,4)
#    (1,2) (4,3)
#    (2,1) (1,2)
#    (2,1) (2,1)
#    (2,1) (3,4)
#    (2,1) (4,3)
#    (3,4) (3,4)
#    (3,4) (4,3)
#    (4,3) (3,4)
#    (4,3) (4,3)
#  Test A
n = 6
#    n = 6
#    pair n/2 = 3 pair in each result
#    ----------
#    (1,2) (3,4) (5,6)
#    (1,2) (3,4) (6,5)
#    (1,2) (4,3) (3,4)
#    (1,2) (4,3) (4,3)
#    (1,2) (4,3) (5,6)
#    (1,2) (4,3) (6,5)
#    (1,2) (5,6) (5,6)
#    (1,2) (5,6) (6,5)
#    (1,2) (6,5) (5,6)
#    (1,2) (6,5) (6,5)
#    (2,1) (1,2) (3,4)
#    (2,1) (1,2) (4,3)
#    (2,1) (1,2) (5,6)
#    (2,1) (1,2) (6,5)
#    (2,1) (2,1) (1,2)
#    (2,1) (2,1) (2,1)
#    (2,1) (2,1) (3,4)
#    (2,1) (2,1) (4,3)
#    (2,1) (2,1) (5,6)
#    (2,1) (2,1) (6,5)
#    (2,1) (3,4) (3,4)
#    (2,1) (3,4) (4,3)
#    (2,1) (3,4) (5,6)
#    (2,1) (3,4) (6,5)
#    (2,1) (4,3) (3,4)
#    (2,1) (4,3) (4,3)
#    (2,1) (4,3) (5,6)
#    (2,1) (4,3) (6,5)
#    (2,1) (5,6) (3,4)
#    (2,1) (5,6) (4,3)
#    (2,1) (5,6) (5,6)
#    (2,1) (5,6) (6,5)
#    (2,1) (6,5) (5,6)
#    (2,1) (6,5) (6,5)
#    (3,4) (3,4) (5,6)
#    (3,4) (3,4) (6,5)
#    (3,4) (4,3) (3,4)
#    (3,4) (4,3) (4,3)
#    (3,4) (4,3) (5,6)
#    (3,4) (4,3) (6,5)
#    (3,4) (5,6) (5,6)
#    (3,4) (5,6) (6,5)
#    (3,4) (6,5) (5,6)
#    (3,4) (6,5) (6,5)
#    (4,3) (3,4) (5,6)
#    (4,3) (3,4) (6,5)
#    (4,3) (4,3) (3,4)
#    (4,3) (4,3) (4,3)
#    (4,3) (4,3) (5,6)
#    (4,3) (4,3) (6,5)
#    (4,3) (5,6) (5,6)
#    (4,3) (5,6) (6,5)
#    (4,3) (6,5) (5,6)
#    (4,3) (6,5) (6,5)
#    (5,6) (3,4) (5,6)
#    (5,6) (3,4) (6,5)
#    (5,6) (4,3) (3,4)
#    (5,6) (4,3) (4,3)
#    (5,6) (4,3) (5,6)
#    (5,6) (4,3) (6,5)
#    (5,6) (5,6) (5,6)
#    (5,6) (5,6) (6,5)
#    (5,6) (6,5) (5,6)
#    (5,6) (6,5) (6,5)
#    (6,5) (6,5) (5,6)
#    (6,5) (6,5) (6,5)
#  Test B
end

main()

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
// Scala program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination()
{
def subSequences(result: Array[Int],
start: Int, count: Int,
n: Int): Unit = {
if (count == n)
{
var i: Int = 0;
// Display resultant sequence
while (i < n - 1)
{
print("(" + result(i) + "," +
result(i + 1) + ") ");
i += 2;
}
print("\n");
}
else if (count > n)
{
return;
}
else
{
var i: Int = start;
while (i < n)
{
// Set pair element
result(count) = i + 1;
result(count + 1) = i + 2;
subSequences(result,
start + 2,
count + 2,
n);
result(count) = i + 2;
result(count + 1) = i + 1;
subSequences(result, i, count + 2, n);
i += 2;
}
}
}
def pairDifferences1s(n: Int): Unit = {
if (n % 2 != 0)
{
print("\n Given n : " + n + " is not even \n");
}
if (n <= 0)
{
return;
}
print(" Given : " + n + " \n");
// Auxiliary array which is collect result
var result: Array[Int] = Array.fill[Int](n)(0);
subSequences(result, 0, 0, n);
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Combination = new Combination();
//  Length and natural number 1..n
var n: Int = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)
// Swift 4 program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination
{
func subSequences(_ result: inout[Int],
_ start: Int,
_ count: Int,
_ n: Int)
{
if (count == n)
{
var i: Int = 0;
// Display resultant sequence
while (i < n - 1)
{
print("(", result[i] ,",",
result[i + 1] ,") ",
terminator: "");
i += 2;
}
print(terminator: "\n");
}
else if (count > n)
{
return;
}
else
{
var i: Int = start;
while (i < n)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
self.subSequences(&result, start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
self.subSequences(&result, i, count + 2, n);
i += 2;
}
}
}
func pairDifferences1s(_ n: Int)
{
if (n % 2  != 0)
{
print("\n Given n : ", n ," is not even ");
}
if (n <= 0)
{
return;
}
print(" Given : ", n ," ");
// Auxiliary array which is collect result
var result: [Int] = Array(repeating: 0, count: n);
self.subSequences(&result, 0, 0, n);
}
}
func main()
{
//  Length and natural number 1..n
var n: Int = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}
main();

#### Output

Given :  4
( 1 , 2 ) ( 3 , 4 )
( 1 , 2 ) ( 4 , 3 )
( 2 , 1 ) ( 1 , 2 )
( 2 , 1 ) ( 2 , 1 )
( 2 , 1 ) ( 3 , 4 )
( 2 , 1 ) ( 4 , 3 )
( 3 , 4 ) ( 3 , 4 )
( 3 , 4 ) ( 4 , 3 )
( 4 , 3 ) ( 3 , 4 )
( 4 , 3 ) ( 4 , 3 )
Given :  6
( 1 , 2 ) ( 3 , 4 ) ( 5 , 6 )
( 1 , 2 ) ( 3 , 4 ) ( 6 , 5 )
( 1 , 2 ) ( 4 , 3 ) ( 3 , 4 )
( 1 , 2 ) ( 4 , 3 ) ( 4 , 3 )
( 1 , 2 ) ( 4 , 3 ) ( 5 , 6 )
( 1 , 2 ) ( 4 , 3 ) ( 6 , 5 )
( 1 , 2 ) ( 5 , 6 ) ( 5 , 6 )
( 1 , 2 ) ( 5 , 6 ) ( 6 , 5 )
( 1 , 2 ) ( 6 , 5 ) ( 5 , 6 )
( 1 , 2 ) ( 6 , 5 ) ( 6 , 5 )
( 2 , 1 ) ( 1 , 2 ) ( 3 , 4 )
( 2 , 1 ) ( 1 , 2 ) ( 4 , 3 )
( 2 , 1 ) ( 1 , 2 ) ( 5 , 6 )
( 2 , 1 ) ( 1 , 2 ) ( 6 , 5 )
( 2 , 1 ) ( 2 , 1 ) ( 1 , 2 )
( 2 , 1 ) ( 2 , 1 ) ( 2 , 1 )
( 2 , 1 ) ( 2 , 1 ) ( 3 , 4 )
( 2 , 1 ) ( 2 , 1 ) ( 4 , 3 )
( 2 , 1 ) ( 2 , 1 ) ( 5 , 6 )
( 2 , 1 ) ( 2 , 1 ) ( 6 , 5 )
( 2 , 1 ) ( 3 , 4 ) ( 3 , 4 )
( 2 , 1 ) ( 3 , 4 ) ( 4 , 3 )
( 2 , 1 ) ( 3 , 4 ) ( 5 , 6 )
( 2 , 1 ) ( 3 , 4 ) ( 6 , 5 )
( 2 , 1 ) ( 4 , 3 ) ( 3 , 4 )
( 2 , 1 ) ( 4 , 3 ) ( 4 , 3 )
( 2 , 1 ) ( 4 , 3 ) ( 5 , 6 )
( 2 , 1 ) ( 4 , 3 ) ( 6 , 5 )
( 2 , 1 ) ( 5 , 6 ) ( 3 , 4 )
( 2 , 1 ) ( 5 , 6 ) ( 4 , 3 )
( 2 , 1 ) ( 5 , 6 ) ( 5 , 6 )
( 2 , 1 ) ( 5 , 6 ) ( 6 , 5 )
( 2 , 1 ) ( 6 , 5 ) ( 5 , 6 )
( 2 , 1 ) ( 6 , 5 ) ( 6 , 5 )
( 3 , 4 ) ( 3 , 4 ) ( 5 , 6 )
( 3 , 4 ) ( 3 , 4 ) ( 6 , 5 )
( 3 , 4 ) ( 4 , 3 ) ( 3 , 4 )
( 3 , 4 ) ( 4 , 3 ) ( 4 , 3 )
( 3 , 4 ) ( 4 , 3 ) ( 5 , 6 )
( 3 , 4 ) ( 4 , 3 ) ( 6 , 5 )
( 3 , 4 ) ( 5 , 6 ) ( 5 , 6 )
( 3 , 4 ) ( 5 , 6 ) ( 6 , 5 )
( 3 , 4 ) ( 6 , 5 ) ( 5 , 6 )
( 3 , 4 ) ( 6 , 5 ) ( 6 , 5 )
( 4 , 3 ) ( 3 , 4 ) ( 5 , 6 )
( 4 , 3 ) ( 3 , 4 ) ( 6 , 5 )
( 4 , 3 ) ( 4 , 3 ) ( 3 , 4 )
( 4 , 3 ) ( 4 , 3 ) ( 4 , 3 )
( 4 , 3 ) ( 4 , 3 ) ( 5 , 6 )
( 4 , 3 ) ( 4 , 3 ) ( 6 , 5 )
( 4 , 3 ) ( 5 , 6 ) ( 5 , 6 )
( 4 , 3 ) ( 5 , 6 ) ( 6 , 5 )
( 4 , 3 ) ( 6 , 5 ) ( 5 , 6 )
( 4 , 3 ) ( 6 , 5 ) ( 6 , 5 )
( 5 , 6 ) ( 3 , 4 ) ( 5 , 6 )
( 5 , 6 ) ( 3 , 4 ) ( 6 , 5 )
( 5 , 6 ) ( 4 , 3 ) ( 3 , 4 )
( 5 , 6 ) ( 4 , 3 ) ( 4 , 3 )
( 5 , 6 ) ( 4 , 3 ) ( 5 , 6 )
( 5 , 6 ) ( 4 , 3 ) ( 6 , 5 )
( 5 , 6 ) ( 5 , 6 ) ( 5 , 6 )
( 5 , 6 ) ( 5 , 6 ) ( 6 , 5 )
( 5 , 6 ) ( 6 , 5 ) ( 5 , 6 )
( 5 , 6 ) ( 6 , 5 ) ( 6 , 5 )
( 6 , 5 ) ( 6 , 5 ) ( 5 , 6 )
( 6 , 5 ) ( 6 , 5 ) ( 6 , 5 )
// Kotlin program for
// Print all combinations of n natural number
// whose pair element difference is one
class Combination
{
fun subSequences(result: Array < Int > ,
start: Int,
count: Int,
n: Int): Unit
{
if (count == n)
{
var i: Int = 0;
// Display resultant sequence
while (i < n - 1)
{
print("(" + result[i] + "," +
result[i + 1] + ") ");
i += 2;
}
print("\n");
}
else if (count > n)
{
return;
}
else
{
var i: Int = start;
while (i < n)
{
// Set pair element
result[count] = i + 1;
result[count + 1] = i + 2;
this.subSequences(result, start + 2, count + 2, n);
result[count] = i + 2;
result[count + 1] = i + 1;
this.subSequences(result, i, count + 2, n);
i += 2;
}
}
}
fun pairDifferences1s(n: Int): Unit
{
if (n % 2 != 0)
{
print("\n Given n : " + n + " is not even \n");
}
if (n <= 0)
{
return;
}
print(" Given : " + n + " \n");
// Auxiliary array which is collect result
val result: Array < Int > = Array(n)
{
0
};
this.subSequences(result, 0, 0, n);
}
}
fun main(args: Array < String > ): Unit
{
//  Length and natural number 1..n
var n: Int = 4;
/*
n = 4
----------
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)

*/
// Test A
n = 6;
/*
n = 6
pair n/2 = 3 pair in each result
----------
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

*/
// Test B
}

#### Output

Given : 4
(1,2) (3,4)
(1,2) (4,3)
(2,1) (1,2)
(2,1) (2,1)
(2,1) (3,4)
(2,1) (4,3)
(3,4) (3,4)
(3,4) (4,3)
(4,3) (3,4)
(4,3) (4,3)
Given : 6
(1,2) (3,4) (5,6)
(1,2) (3,4) (6,5)
(1,2) (4,3) (3,4)
(1,2) (4,3) (4,3)
(1,2) (4,3) (5,6)
(1,2) (4,3) (6,5)
(1,2) (5,6) (5,6)
(1,2) (5,6) (6,5)
(1,2) (6,5) (5,6)
(1,2) (6,5) (6,5)
(2,1) (1,2) (3,4)
(2,1) (1,2) (4,3)
(2,1) (1,2) (5,6)
(2,1) (1,2) (6,5)
(2,1) (2,1) (1,2)
(2,1) (2,1) (2,1)
(2,1) (2,1) (3,4)
(2,1) (2,1) (4,3)
(2,1) (2,1) (5,6)
(2,1) (2,1) (6,5)
(2,1) (3,4) (3,4)
(2,1) (3,4) (4,3)
(2,1) (3,4) (5,6)
(2,1) (3,4) (6,5)
(2,1) (4,3) (3,4)
(2,1) (4,3) (4,3)
(2,1) (4,3) (5,6)
(2,1) (4,3) (6,5)
(2,1) (5,6) (3,4)
(2,1) (5,6) (4,3)
(2,1) (5,6) (5,6)
(2,1) (5,6) (6,5)
(2,1) (6,5) (5,6)
(2,1) (6,5) (6,5)
(3,4) (3,4) (5,6)
(3,4) (3,4) (6,5)
(3,4) (4,3) (3,4)
(3,4) (4,3) (4,3)
(3,4) (4,3) (5,6)
(3,4) (4,3) (6,5)
(3,4) (5,6) (5,6)
(3,4) (5,6) (6,5)
(3,4) (6,5) (5,6)
(3,4) (6,5) (6,5)
(4,3) (3,4) (5,6)
(4,3) (3,4) (6,5)
(4,3) (4,3) (3,4)
(4,3) (4,3) (4,3)
(4,3) (4,3) (5,6)
(4,3) (4,3) (6,5)
(4,3) (5,6) (5,6)
(4,3) (5,6) (6,5)
(4,3) (6,5) (5,6)
(4,3) (6,5) (6,5)
(5,6) (3,4) (5,6)
(5,6) (3,4) (6,5)
(5,6) (4,3) (3,4)
(5,6) (4,3) (4,3)
(5,6) (4,3) (5,6)
(5,6) (4,3) (6,5)
(5,6) (5,6) (5,6)
(5,6) (5,6) (6,5)
(5,6) (6,5) (5,6)
(5,6) (6,5) (6,5)
(6,5) (6,5) (5,6)
(6,5) (6,5) (6,5)

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.