brennahan
BAN USER... As nice and elegant as this is, you still have to have a preconceived idea of where they are in order to decode from any given bit representation among all of them... which would require more bits to store that info. X_X
I mean if having extra information outside of the bit-representation is allowed this is a wonderful solution. If not, then you're trying to mash 2016 different combinations into a bit representation that at max holds 1024 and I'm not entirely sure if its possible.
Edit: tl;dr Given only the bit-representation, there is no schema to fit 2016 explicit combinations into 1024 slots using bit-representation.
I made a C# method for it. This appears to work and I BELIEVE it'll cover cases that result from larger strings also. Little bit lengthy, but recursive method seemed most logical to handle the total number of removed characters. There's obviously driver code, but its not all that important.
public static int testPalin(string palin)
{
if (start == end || start > end) { return 0; }
else if (palin[start] == palin[end])
{
start++; end--;
return testPalin(palin);
}
else
{
int depth = 1;
while (depth <= max)
{
if (palin[start + 1 + (depth - 1)] == palin[end - (depth - 1)])
{
start += depth + depth - 1;
end -= depth - 1;
return 2 * depth - 1 + testPalin(palin);
}
else if (palin[start + (depth - 1)] == palin[end - 1 - (depth - 1)])
{
start += depth - 1;
end -= depth + depth - 1;
return 2 * depth - 1 + testPalin(palin);
}
else if (palin[start + 1 + (depth - 1)] == palin[end - 1 - (depth - 1)])
{
start += depth + depth - 1;
end -= depth + depth - 1;
return 2 * depth + testPalin(palin);
}
else if (depth < max)
depth++;
else
return depth; //No palindrome possible with current max removable nums.
}
}
return 1; //The code gets fussy about making sure there's a return, so I put it in to shit it up.
}
(I am Bren, just logged in to acct.)
The only other way I can think of is the case where order does not matter. In this case, you can have a base piece and a moving piece. The base piece sits on a spot, and the moving piece would cover the rest of the "NEW" combinations of spots. This mean you just have a summation for the total combination. 63 summation comes out to 2016 possible combinations, though again, you would still need 11 bits to cover it all.
C#:
- brennahan October 04, 2013