Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4499

Re: Calcul XOR : array , times.

From Harry Kakueki <list.push@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Calcul XOR : array , times.
Date 2011-05-13 10:17 -0500
Organization Service de news de lacave.net
Message-ID <BANLkTimJsgZPt6aGctrL6kYxS+DhC0P-aA@mail.gmail.com> (permalink)
References <a7cc430dc5fa3e0403b87599dcb06dc2@ruby-forum.com>

Show all headers | View raw


On Fri, May 13, 2011 at 9:25 PM, aix aix <ruby.aix@gmail.com> wrote:
> Hello ,
>
> I have problems with my code for XOR calcul :
>
>    a = [1, 0, 1, 1, 0, 0, 1]
>    b = ["101101", "101100", "110011", "000111", "010110"]
>    # good result : 000001, 011010,101000, 001010,110000
>    # false result : ["000001", "000000", "011111", "101011", "111010"]

>
> How to use a[6] as above ?
>


Sorry, I did not look for a problem with your code. I did it another way.
This is not tested so it may have some problems but maybe it will give
you some ideas.

a = [1, 0, 1, 1, 0, 0, 1]
b = ["101101", "101100", "110011", "000111", "010110"]

bmod = b.join.split(//).map{|x| x.to_i}
amod = a*(bmod.size/a.size+1)
res = amod[0...bmod.size].zip(bmod).map{|z| z[0]^z[1]}

p [].tap{|y| b.size.times{y << res.slice!(0...b[0].size)}}.map{|g| g.join}




Harry

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Calcul XOR : array , times. aix aix <ruby.aix@gmail.com> - 2011-05-13 07:25 -0500
  Re: Calcul XOR : array , times. Harry Kakueki <list.push@gmail.com> - 2011-05-13 10:17 -0500
  Re: Calcul XOR : array , times. 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-13 13:22 -0500
    Re: Calcul XOR : array , times. 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-13 13:43 -0500

csiph-web