Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4499
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail |
|---|---|
| From | Harry Kakueki <list.push@gmail.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: Calcul XOR : array , times. |
| Date | Fri, 13 May 2011 10:17:30 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 34 |
| Message-ID | <BANLkTimJsgZPt6aGctrL6kYxS+DhC0P-aA@mail.gmail.com> (permalink) |
| References | <a7cc430dc5fa3e0403b87599dcb06dc2@ruby-forum.com> |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | Quoted-printable |
| X-Trace | talisker.lacave.net 1305300669 37950 65.111.164.187 (13 May 2011 15:31:09 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Fri, 13 May 2011 15:31:09 +0000 (UTC) |
| In-Reply-To | <a7cc430dc5fa3e0403b87599dcb06dc2@ruby-forum.com> |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 383214 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <BANLkTimJsgZPt6aGctrL6kYxS+DhC0P-aA@mail.gmail.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:4499 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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