[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6217] Re: Ruby hi(gh), and pointer to Jotto program

From: Dave Thomas <Dave@...>
Date: 2000-11-09 16:51:53 UTC
List: ruby-talk #6217
David Alan Black <dblack@candle.superlink.net> writes:

> On Thu, 9 Nov 2000, Dave Thomas wrote:
> >      def common4(w1, w2)
> >        c = 0
> >        w1.each_with_index { |ch, i| c += 1 if w2[i] == ch }
> >        c
> >      end
> 
> But doesn't that just split (inclusively) on $/, rather than
> interating through the characters?  If only $/ could be a regular
> expression.... but then it would perhaps only do as well as:

Yup - I'm totally wrong on that one. Also, I just tried it with
String#each_byte and it was slower than the others.

It occurs to me that a speedup might be possible in the Jotto case
because one of the words is always fixed (for each side of the game)
so you could create a counter object and just pass it the word to be
checked:

     class Common5
       def initialize(word)
         @word = word
         @len = word.length
       end

       def count(word)
         i = 0
         count = 0
         @len.times {|i| count += 1 if word[i] == @word[i] }
         count
       end
     end
     c = Common5.new("hello dave")

     bm(10) {|x|
       x.report { 10000.times { common1("hello dave", "wombo dxve") } }
       x.report { 10000.times { common2("hello dave", "wombo dxve") } }
       x.report { 10000.times { common3("hello dave", "wombo dxve") } }
       x.report { 10000.times { common4("hello dave", "wombo dxve") } }
       x.report { 10000.times { c.count("wombo dxve") } }
     }

For me, that runs as fast as the fastest function-based test. I'm sure
there's a clever algorithm that could be implemented by
pre-calculating stuff in Common5, much as Boyer-Moore speeds up string
searching by pre-computing gaps. However, getting a clever algorithm
would require me to be either lucky or clever, and I'm neither today.


Regards


Dave

In This Thread