Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing chars in array, by columns?

 
Lucas McLevinsky
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! My first topic here, haha. I have a question about comparing char values in an array with another array, however a bit differently:

Let's say I have a first array like this
0 0 1 0 1 0 1 0 1 0 1
0 0 1 1 1 1 0 0 1 0 1
0 0 0 1 0 1 0 1 0 1 0
And the second
0 1 1 1 0 0 0 1 0 1 0

Now I want to compare the value of the first index from the second array with the ENTIRE column of the first array - in other words I want to compare
[0] 0 1 0 1 0 1 0 1 0 1
[0] 0 1 1 1 1 0 0 1 0 1
[0] 0 0 1 0 1 0 1 0 1 0 - all three of those
with
[0] 1 1 1 0 0 0 1 0 1 0

And return 1 if they are all the same, 0 if they are different values, and 2 if the values from the corresponding column from the first array are all inversed values from the second (i.e. comparing "1" from the second array to all "0"'s from the first). And do this as many times, as the number of characters in the second array (in this case - 11)

Any clue how to do this? I need it as a part of an important project for me and I'd appreciate any help!

Cheers,
Lucas.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what have you tried?

Your first array looks like an array of arrays, and with that all you'd have to look at is the first value of each array and compare that to whatever value.
 
Campbell Ritchie
Sheriff
Posts: 48406
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Since you have an array of arrays, you can use each element of it as an array in its own right.
I think you need to turn your computer off, and write down on paper how you intend to compare those arrays.
 
Winston Gutkowski
Bartender
Pie
Posts: 10109
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucas McLevinsky wrote:And return 1 if they are all the same, 0 if they are different values, and 2 if the values from the corresponding column from the first array are all inversed values from the second (i.e. comparing "1" from the second array to all "0"'s from the first). And do this as many times, as the number of characters in the second array (in this case - 11)

Well, other than the good advice you've already been given, I have a few further tips.

1. When you're working out what you want to do: start with a single column, and describe exactly what you want to happen in English (or your native language), NOT in code-speak. Once you have that, you should be able to simply wrap it in a "for each column" loop.

2. What you've shown us look like binary digits rather than characters, so make them booleans, even if it means converting them first. If they really are characters, and they can contain values other than '1' and '0', then you need to explain exactly what you mean by "inversed values".

3. In your example, all arrays are the same length; but what if they aren't? Make sure you have a 'Plan B' for when input is invalid, even if it's just to let the program fail.

Winston
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic