wow...this really is excellent use of regex.
I also used regex but then iterated over the list of words and tried to
match every word.

I think the magic is in the use of modifier "m" that I think makes it return
list of all matched words in the array.

One question though...instead of this line:
@res    = $dstr =~ /$str/gm;

if I use:
$res = $dstr =~ /$str/gm;

will it directly return the count of matches? As the array in scalar context
returns the length of array?

I am going to try this out at the first opportunity I get.

~KeJo

On Fri, Sep 4, 2009 at 9:28 PM, Dhruva Sagar <[email protected]> wrote:

> Wow...I have difficulty understanding how it returns the count.
>
> Thanks & Regards,
> Dhruva Sagar.
>
>
> Ted Turner <http://www.brainyquote.com/quotes/authors/t/ted_turner.html> - 
> "Sports is like a war without the killing."
>
> On Fri, Sep 4, 2009 at 9:25 PM, krzych <[email protected]> wrote:
>
>>
>> This is part of my code:
>>
>> @res    = $dstr =~ /$str/gm;
>> print 'Case #'.($cnt+1).': '....@res."\n";
>>
>> $dstr is comma separated list of words, $str is my computed
>> expression. @res is the results array, when evaluated as scalar (as in
>> second line), it will give number of elements (matches). That's all.
>>
>>
>> On Sep 4, 5:36 pm, Dhruva Sagar <[email protected]> wrote:
>> > No my friend, maybe you have the wrong idea, RegExp won'g help you
>> count,
>> > but only test, here is my code in Ruby :
>> > It should be pretty easy to understand.
>> >
>> > N.times do |i|
>> >   r = Regexp.new(input[i+D+1].gsub('(','[').gsub(')',']').to_s)
>> >   count = 0
>> >   words.each do |w|
>> >     count+=1 if !r.match(w).nil?
>> >   end
>> >   output.puts "Case ##{i}: #{count}\n"
>> > end
>> >
>> > Thanks & Regards,
>> > Dhruva Sagar.
>> >
>> > Ogden Nash <http://www.brainyquote.com/quotes/authors/o/ogden_nash.html>
>>  -
>> > "The trouble with a kitten is that when it grows up, it's always a cat."
>> >
>> > On Fri, Sep 4, 2009 at 8:40 PM, Satyajit Malugu
>> > <[email protected]>wrote:
>> >
>> >
>> >
>> > > You guys are all damn good at regex's I think. For the life of me, I
>> simply
>> > > thought regex's can't be done because I have to count the number of
>> > > matches.
>> > > Can you give the regex you've used?
>> >
>> > > On Fri, Sep 4, 2009 at 5:21 AM, krzych <[email protected]> wrote:
>> >
>> > >> Hi,
>> >
>> > >> I solved first problem correctly in Perl for both small and large
>> data
>> > >> sets. I just used regular expression and I think that this was the
>> > >> easiest (and requiring only a few lines of code) way to solve this
>> > >> task. Since I'm not familiar with Perl I had some problems and my
>> > >> regular expression is overcomplicated, but since it was working, I
>> > >> left it like it was.
>> >
>> > >> Cheers,
>> > >> Krzysztof.
>> >
>> > >> On Sep 4, 10:50 am, KeJo <[email protected]> wrote:
>> > >> > Hi,
>> >
>> > >> > anyone solved all problems correctly using perl?
>> >
>> > >> > I did it, but I feel there could be better ways to do it in perl.
>> > >> > Please let me know so that I can compare.
>> >
>> > >> > Regards,
>> > >> > KeJo
>> >
>> > > --
>> > > Satyajit
>>
>>
>
> >
>


-- 
Blog: http://beingkejo.wordpress.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to