We are given N rectangular frames of different sizes (duplicates are allowed). Write a program to find all unique ways we can reorder these frames by exchanging their order and flipping them.
Input:
3
2 3
2 2
3 2
Output:
12
(2, 2) | (2, 3) | (2, 3)
(2, 2) | (2, 3) | (3, 2)
(2, 2) | (3, 2) | (2, 3)
(2, 2) | (3, 2) | (3, 2)
(2, 3) | (2, 2) | (2, 3)
(2, 3) | (2, 2) | (3, 2)
(2, 3) | (2, 3) | (2, 2)
(2, 3) | (3, 2) | (2, 2)
(3, 2) | (2, 2) | (2, 3)
(3, 2) | (2, 2) | (3, 2)
(3, 2) | (2, 3) | (2, 2)
(3, 2) | (3, 2) | (2, 2)
Here is my code so far in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frames
{
class Program
{
static void Main()
{
var n = int.Parse(Console.ReadLine());
var frames = new Tuple<int, int>[n * 2];
for (int i = 0; i < n * 2; i += 2)
{
var strs = Console.ReadLine().Split(' ');
frames[i] = new Tuple<int, int>(int.Parse(strs[0]), int.Parse(strs[1]));
frames[i + 1] = new Tuple<int, int>(frames[i].Item2, frames[i].Item1);
}
Array.Sort(frames);
Recursion(frames, 0, n, new Tuple<int, int>[n], new bool[frames.Length]);
}
static void Recursion(Tuple<int, int>[] frames, int position, int n, Tuple<int, int>[] current, bool[] used)
{
if (position == n)
{
Console.WriteLine(string.Join(" | ", (IEnumerable<Tuple<int, int>>)current));
return;
}
for (int i = 0; i < frames.Length - 1; i++)
{
if (used[i])
{
continue;
}
used[i] = true;
current[position] = frames[i];
Recursion(frames, position + 1, n, current, used);
used[i] = false;
}
}
}
}
I can't seem to figure out how to treat both rotations of the frame as used and then exclude duplicates. Any directions would be appreciated.