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 :
>
> =A0 =A0a =3D [1, 0, 1, 1, 0, 0, 1]
> =A0 =A0b =3D ["101101", "101100", "110011", "000111", "010110"]
> =A0 =A0# good result : 000001, 011010,101000, 001010,110000
> =A0 =A0# 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 =3D [1, 0, 1, 1, 0, 0, 1]
b =3D ["101101", "101100", "110011", "000111", "010110"]

bmod =3D b.join.split(//).map{|x| x.to_i}
amod =3D a*(bmod.size/a.size+1)
res =3D 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