# Detect parity error in rows and columns (any length)

Learning outcomes Students will be able to:

## Requirement:

Write a program that asks the user to enter the number of rows for a parity trick followed by the rows (one row at a time) as the input and says which row and column has a parity error as the output. We are assuming that only one card has been flipped over (i.e. there is only one row and one column with error). You will need to use a list to store the rows for this challenge.

## Testing examples:

Your program should display the outputs shown in these panels for the given inputs provided:

Input Output
How many rows would you like to enter? 6
Enter 6 cards for row 1: WBBWWW
Enter 6 cards for row 2: BBWBWB
Enter 6 cards for row 3: BWWWBW
Enter 6 cards for row 4: BBBBBB
Enter 6 cards for row 5: WBBWWB
Enter 6 cards for row 6: BBBWBB
There is a parity error in row 5 and column 2.
How many rows would you like to enter? 4
Enter 4 cards for row 1: BWWB
Enter 4 cards for row 2: BBBB
Enter 4 cards for row 3: WBBB
Enter 4 cards for row 4: WBWB
There is a parity error in row 3 and column 2.

## Languages

Scratch #### What it should look like

Click on the green flag, enter the inputs provided in the “testing examples” to see the expected output of your program.

Recommended blocks
when green flag clicked

delete (all v) of [cards v]

say (join (join (join [There is a parity error in row ] (error in row)) [ and column ]) (error in column))
change [black cards total v] by (1)

change [row index v] by (1)

set [error in column v] to (index)

change [index v] by (1)

set [black cards total v] to 

set [row index v] to 

set [index v] to 

change [row number v] by (1)

set [error in row v] to (row number)

change [index v] by (1)

set [black cards total v] to 

set [index v] to 

set [row number v] to 

set [error in row v] to 

set [error in column v] to 

set [number of rows v] to (answer)

change [black cards total v] by (1)
ask (join (join (join [Enter ] (number of rows)) [ cards for row ]) (row number)) and wait

ask [How many rows would you like to enter?] and wait
repeat (number of rows)
end

repeat (length of (row))
end

if <(letter (index) of (row)) = [B]> then
end

if <((black cards total) mod (2)) = > then
end

repeat (number of rows)
end

repeat (number of rows)
end

if <(letter (index) of (item (row index) of [cards v] :: list)) = [B]> then
end

if <((black cards total) mod (2)) = > then
end
Hints
• For this challenge you need to use a list to store all the rows (each item in the list is a row). You then need to go through each item of your list and check if they have an error (i.e. the total number of black cards in each row are odd). If there is a parity error in any of the rows you then need to store its position in the list in a variable called “error in row”.

• You then need to check if there are any parity errors in any of the columns. To check this for the first column you need to go through the first letters of all the items in your list and check if the total number of black cards are odd (i.e. there is a parity error in that column). You then need to repeat this for all the other columns. If you find a parity error in any of the columns store it in a variable called “error in column”

• Display the values for “error in row” and “error in column” at the end of your program as the output.

• To make a new list select “Make a list” under “Data” script.

• Add items to your list by using the add () to [cards v] block.

• You can access an item in a specific position in your list by using the item () of [cards v] :: list block.

• The length of [cards v] :: list block reports how many items are in the list.

• You need to delete all the previous items from your list at the start of your program. If you don’t do this, your new items get added to the list every time you run your program. To delete all the items from your list select “all” from the drop down list on the delete (all v) of [cards v] block.

• You can access a letter at the specified position in a string by using the letter (1) of [world] block under “Operators”. For example: letter (1) of [world] //w

• In this challenge you need to access all the letters in user’s input (each row of the parity trick) and check to see how many of them are equal to B (black). Store the total number of black squares in a variable called “black cards total”.

• You can find how many letters a string has by using the length of [world] block unders “Operators”.

• To find out if a number is even or odd, use the () mod () block (under "Operators") to find the remainder after dividing that number by two. If the remainder is zero the number is even. For example: (37) mod (10) //7

## Extra Challenge

For the extra challenge you need to check if the number of cards in each row (number of columns) is equal the total number of rows (i.e. if you have 6 rows each row must contain 6 cards).