what are the parity bits in a 7,3 linear code - bit

If I have a linear (7,4)-Hamming Code I know that the last 3 bits are the parity bits but I just have seen that there are multiple Codes like (7,3) for example (this should represent a matrix):
1 0 0 1 0 0 0
1 0 0 0 0 0 1
1 0 1 0 1 0 0 (Notice that it's not important if this is correct or not)
Are the first 3 bits the parity bits and the last four the information words? Or how can I understand this matrix?
Thank You very much for your help!

Related

find the path with least number of jumps for a frog crossing pond using divide and conquer

A frog is trying to cross a pond but he can only jumps on stones and he can jump up to five units.
We have been given an array with ones and zeros (zeros for water and ones for stones) and the task to find the best possible approach to find the path with the least number of jump(using divide and conquer if possible).
Example for array -> [0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 0]
p.s: the frog starts one unit before the array and have to reach a unit after the array (it is possible that there is no path available with conditions mentioned)
I'm just starting to learn algorithms so it would be nice if you guys help me with the algorithm and code.
My idea for a divide and conquer approach would be the following:
program frog(array)
begin
divide array after the '1' left of the center of the array;
foreach (partialArray) do begin
if (length(partialArray) > 5) then frog(partialArray);
end foreach;
end.
Let's use your given array as an example: [0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 0]
1st division: [0 0 0 1 0 0 1 0 0 1|0 1 0 0 1 0 1 1 0 0 0 0]
2nd division: [0 0 0 1|0 0 1 0 0 1|0 1 0 0 1|0 1 1 0 0 0 0]
3rd division: [0 0 0 1|0 0 1|0 0 1|0 1 0 0 1|0 1 1|0 0 0 0]
In this case, the frog would jump to the first, the second, the third, the fifth, and the seventh 1 before reaching the goal (= 6 jumps).
Why does this algorithm work? Let's assume, it wouldn't output a shortest way of jumping for the frog. That would mean, we didn't find the partialArrays with the largest jumps for the frog. If one partialArray wouldn't resemble a largest jump, that would mean: There would be at least one 1 after the 1 inside the partialArray which the frog can still reach. This isn't possible, since length(partialArray) ≤ 5 holds. Thus, every 1 after the partialArray would be too far away (> 5).

How to make all entries of 4x4 matrix to either 1 or 0 when only one operation is allowed?

I have a 4x4 matrix. Say
0 1 1 0
0 0 1 0
0 1 1 0
0 1 1 1
My task is to transform the matrix to either
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
or
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Single operation is defined as pick any element of the matrix and then replace the element and elements to its left, right, up and down with their xor with 1.
Example
0 1 1 0
0 0 1 0
0 1 1 0
0 1 1 1
operation on marked element will transform the matrix to
0 1 0 0
0 1 0 1
0 1 0 0
0 1 1 1
My objective is to calculate the minimum number of operations needed to get the final result.
I don't even understand under what category this problem lies? Is this branch and bound, bactracking or something else.
What you've described is called lights out puzzle. There's relevant OEIS that gives you the minimal number of nontrivial switch flippings needed to solve the all-ones lights out problem on an n X n square.
Wikipedia describes a general sketch of algorithm how to solve it. You might be also interested in this answer here on SO, which includes a link to example implementation. Citing the answer:
The idea is to set up a matrix representing the button presses a column vector representing the lights and then to use standard matrix simplification techniques to determine which buttons to press. It runs in polynomial time and does not require any backtracking.

Find cluster boundary in given matrix

Given matrix contains many clusters. Cluster is represented by 1's.
For Example:
0 1 1 1 0
1 1 1 0 0
0 0 0 1 1
1 1 0 0 1
In this example, there are 3 clusters (connected 1's horizontally or vertically).
Now suppose that matrix size is very big and it contains too many clusters.
Now my question is, I want to know the boundary of all the clusters.
For example given matrix:
0 0 1 1 0
0 1 1 1 1
0 0 1 1 0
0 0 0 1 0
Now output should be coordinates of bold locations:
0 0 1 1 0
0 1 1 1 1
0 0 1 1 0
0 0 0 1 0
Consider matrix is huge with many such clusters, suggest optimized way of finding boundaries of all clusters.
A 1 is on the boundary of some cluster only when it has an 0 as one of its immediate neighbors or when it's on the outline of the matrix, so the naive method would be outputting the coordinates of 1's on the outline, then going through all the other matrix cells and outputting the coordinates of 1's satisfying the said condition.
It doesn't look like there is a way to optimize this algorithm, though.
Suppose we have a huge matrix with only one random 1 inside it. There is no way to find it without going through each and every cell out there.
There is also no way to skip 1's of the same cluster by following the outline of it.
Consider this example:
0 0 0 1 1 1 1 1 1 1
0 0 0 1 0 0 0 0 0 1
0 1 1 1 1 1 0 1 0 1
0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 1 1 1 1
One cluster can easily fit inside another one, so following the outline is not an option.

create multiple NxM matrices

I'm looking for a code which returns all combinations of NxM matrices consisting of only ones and zeros. Every row contains precisely one '1'. Every column consists of one or more '1'. If the rules for rows and columns are hard to program they may be left out since computational problem is not going to be an issue.
1 0 0
1 0 0
1 0 0
0 1 0
0 0 1
1 0 0
1 0 0
0 1 0
0 1 0
0 0 1
etc. etc. etc.
Hopefully someone can help me out.
Cheers, Raymond

generating bitboard masks for move

I'm trying to understand how works bitboard representation in chess programming and I can't find usefull information (or just can't translate it correctly ^^) about one detail. My question is, how to generate automaticly masks for move on every position by every piece. I assume its an matrix where each piece type have define every field he can move from this position (array[5][64] for wP, bP, K, R, N, B). For example for Rook on position below, only allowed positions are:
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
1 1 R 1 1 1 1 1
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
I assume i have to create something like this for each piece type and for every tile it can step but do i have to hardcoded it manually to array or there is some possibility to automatize this process and precompute it after program run?
You could fairly easily precompute all of the bitboards that you need, since the rules of chess are well defined. For example, here is a function (in python) that would compute legal moves for a rook:
import sys
def rook(x, y):
for i in range (1, 9):
for j in range (1, 9):
if x == i or y == j:
sys.stdout.write("1")
else:
sys.stdout.write("0")
sys.stdout.write("\n")
print "Bit board of legal moves for a rook at 1, 3:"
rook(1, 3)
Instead of printing out the bitboard, you would likely store it in a compact format, such as an array of 64 bit values (since an 8x8 board needs 64 bits for each board).
This is a fairly extreme optimization technique, so the details of its implementation are going to get hairy (and be a pain to debug).
I used the wiki bitboard page as reference.

Resources