A square paper is cut into 16 square pieces. Arrange the pieces to get the original form.
7 Answers
Know the answer? Post it. Somebody with the same question will find it here.
VulpesRank #55 · 29.2K reputationPosted Jun 27, 2012, 1:32 AM EDT
✓ Accepted answer0
If all the pieces are of the same size, then it follows that they must be arranged in four rows of four pieces each as that's the only arrangement which is symmetrical.
If we assume that the pieces are numbered 1 to 16 (1 to 4 in the first row, 2 to 7 in the second row etc) and that they've all been shuffled so they are now in random order, we can solve the problem as follows:
using System;
class Paper
{
static Random rand = new Random();
static int[] pieces = new int[16];
static void Main()
{
while(true)
{
Array.Clear(pieces, 0, 16); // resets all elements to 0
// fill the pieces array in a random fashion
int index = 0;
int number;
while (index < 16)
{
number = rand.Next(1, 17); // gets random number between 1 to 16 (excludes endpoint);
// check if it's already been drawn and, if it hasn't put it in the array
if (Array.IndexOf(pieces, number) == -1)
{
pieces[index] = number;
index++;
}
}
// print out random pieces
Console.WriteLine("The unsorted pieces are : \n");
PrintPieces();
// now we need to sort the array to restore the original arrangement
Array.Sort(pieces);
Console.WriteLine("\nThe rearranged pieces are :\n");
PrintPieces();
Console.Write("\nDo another y/n : ");
string yn = Console.ReadLine();
if (yn == "n") return;
Console.WriteLine();
}
}
static void PrintPieces()
{
for (int row = 0; row < 4; row++)
{
for(int col = 0; col < 4; col++)
{
Console.Write(" {0,2} ", pieces[row * 4 + col]);
}
Console.WriteLine();
}
}
}
0
VulpesRank #55 · 29.2K reputationPosted Jun 26, 2012, 7:50 AM EDT
0
Is there some more information on this question - for example, whether we can assume that the pieces are all the same size and are numbered in some way?
If the square pieces can be of arbitrary size (subject to them fitting into the square paper), the question seems far too hard for a beginner or me for that matter!
rani m mk47 reputationPosted Jun 27, 2012, 12:28 AM EDT
0
Yes Vulpes,
All pieces are of same size and cut into 16 pieces.. How do we write the logic to get the original form of the paper(original form being square)
throw new ArgumentException("Argument can't be less than zero");
}
else if (n < 2)
{
return n;
}
else
{
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
}
static void Main()
{
for (int i = 0; i < 36; i++)
{
Console.WriteLine("n = {0} => {1}", i, Fibonacci(i));
}
Console.ReadKey();
}
}
Notice how the Fibonacci method is calling itself recursively in this line:
return Fibonacci(n - 1) + Fibonacci(n - 2);
As I said earlier, I can't see how you could use recursion to solve this 'paper-cutting' problem but if anyone else has any ideas, I'd be interested to hear them.
VulpesRank #55 · 29.2K reputationPosted Jun 27, 2012, 1:32 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 26, 2012, 7:50 AM EDT
If the square pieces can be of arbitrary size (subject to them fitting into the square paper), the question seems far too hard for a beginner or me for that matter!
rani m mk47 reputationPosted Jun 27, 2012, 12:28 AM EDT
rani m mk47 reputationPosted Jun 29, 2012, 8:21 PM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 30, 2012, 2:37 AM EDT
Although you can sometimes rewrite code to use recursion rather than iteration, I don't see how you could do that in any meaningful way here.
rani m mk47 reputationPosted Jul 18, 2012, 8:53 PM EDT
I thought we could use recursion,but i don`t know much about that so thought someone would guide..
VulpesRank #55 · 29.2K reputationPosted Jul 19, 2012, 5:47 AM EDT
The following program computes the numbers in the Fibonacci series (see link below) for values of n from 0 to 35 inclusive:
http://en.wikipedia.org/wiki/Fibonacci_number
Notice how the Fibonacci method is calling itself recursively in this line:
return Fibonacci(n - 1) + Fibonacci(n - 2);
As I said earlier, I can't see how you could use recursion to solve this 'paper-cutting' problem but if anyone else has any ideas, I'd be interested to hear them.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts