• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing chars in array, by columns?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic