Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4511
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Calcul XOR : array , times. |
| Date | 2011-05-13 13:43 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <c15ba9ed49c89eee245ec3239b5f5bcf@ruby-forum.com> (permalink) |
| References | <a7cc430dc5fa3e0403b87599dcb06dc2@ruby-forum.com> <8047b73e0afaafad066d17f440d40cf1@ruby-forum.com> |
7stud -- wrote in post #998575:
> aix aix wrote in post #998497:
>> How to use a[6] as above ?
>>
>> Thanks
>
> You want Array#cycle.
Here's an example using Enumerator#next:
a = [1, 0, 1, 1, 0, 0, 1]
b = ["101101", "101100", "110011", "000111", "010110"]
enum = a.cycle
b.each do |str|
int_arr = str.split(//).map(&:to_i)
result_arr = int_arr.map do |int|
int ^ enum.next
end
p result_arr.join('')
end
--output:--
"000001"
"011010"
"101000"
"001010"
"110000"
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous 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