r/dailyprogrammer • u/rya11111 3 1 • May 25 '12
[5/25/2012] Challenge #57 [intermediate]
Given a 3x3 table where 1 represents on and 0 represents off:
ABC
A010
B111
C011
Where "inverted match" is defined as a case where the values at the coordinates in the format of (X, Y) and (Y, X) are the same, the inverted matches are as follows:
[[(A, B), (B, A)], [(A, C), (C, A)], [(B, C), (C, B)]]
Of these, the matches that have a value of 1 are:
[[(A, B), (B, A)], [(B, C), (C, B)]]
Therefore, there are 2 sets of inverted matches that have a value of 1.
Find the amount of inverted matches in the table in table(below) with a value of 1.
Table:
ABCDEFGHIJKLMNOPQRSTA11110101111011100010B10010010000010001100C01101110010001000000D10110011001011101100E10100100011110110100F01111011000111010010G00011110001011001110H01111000010001001000I01101110010110010011J00101000100010011110K10101001100001100000L01011010011101100110M10110110010101000100N10001111101111110010O11011010010111100110P01000110111101101000Q10011001100010100000R11101011100110110110S00001100000110010101T01000110011100101011
- Thanks to gbchaosmaster for the challenge at /r/dailyprogrammer_ideas :)
UPDATE: I have given some more info on the difficult challenge since it seems to be very tough. you have upto monday to finish all these challenges. pls note it :)
2
u/eruonna May 25 '12 edited May 25 '12
Haskell:
Result:
2
u/Cosmologicon 2 3 May 25 '12
People seem to be assuming we can have the table pre-formatted, so here's a python solution assuming that:
If you need to format it from the given string, you can do it like this:
2
u/Medicalizawhat May 26 '12
My first attempt at an intermediate question… Ruby:
Answer:
1
u/mythealias May 25 '12
Matlab:
where a is the array with given 0s and 1s.
1
u/[deleted] May 25 '12
J:
1
u/emcoffey3 0 0 May 25 '12
Solution in C# assuming pre-formatted int[,] matrix:
Answer for sample input:
1
u/flakmonkey May 26 '12
Python:
1
u/xjtian May 26 '12
Assuming there's a text file with the data matrix in the same format as the test case.
Python:
Answer:
1
u/Steve132 0 1 May 25 '12
Outputs: 120. You weren't clear if (A,A) counts as a match or not. This code pretends that it does. If not, the right answer is 100