I sat and optimized a bit of my code now, apparently it can be much shorter
& a bit quicker.
solution in Ruby :
input = IO.readlines(ARGV[0])
output = File.new('output', 'w')
L = input[0].split(' ')[0].to_i
D = input[0].split(' ')[1].to_i
N = input[0].split(' ')[2].to_i
words = []
1.upto(D) do |i|
words[i-1] = input[i]
end
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
output.close
Thanks & Regards,
Dhruva Sagar.
Stephen
Leacock<http://www.brainyquote.com/quotes/authors/s/stephen_leacock.html>
- "I detest life-insurance agents: they always argue that I shall some
day
die, which is not so."
On Fri, Sep 4, 2009 at 7:41 AM, Monang Setyawan <[email protected]> wrote:
> Did your solution pass the large input? I've tried similar approach first
> but change it to the more appropriate one, since it failed the large input
> case.
>
> On Fri, Sep 4, 2009 at 8:46 AM, Pedro Henrique Calais <
> [email protected]> wrote:
>
>> Yes, they are available on the web site.
>>
>> My solution for problem A was just to convert the words to regexs:
>>
>> (ab)c(cd) --> [ab]c[cd]
>>
>> and then tested the regex against all the vocabulary of the language.
>>
>> -- Pedro
>>
>>
>> On Thu, Sep 3, 2009 at 10:44 PM, Dhruva Sagar <[email protected]>wrote:
>>
>>> I finished only problem A for both small & large :(.
>>> Came close to finishing B, but time ran out.
>>>
>>> Is it possible to see others' solutions ? I would love to.
>>>
>>> Thanks & Regards,
>>> Dhruva Sagar.
>>>
>>>
>>> Pablo
>>> Picasso<http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html> -
>>> "Computers are useless. They can only give you answers."
>>>
>>> On Fri, Sep 4, 2009 at 6:55 AM, MagicLi <[email protected]> wrote:
>>>
>>>>
>>>> I finish problem A&B, for problem C, I finish the small input, my
>>>> program fail the large input. I think there is better algorithm to
>>>> work it out.
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> "Don't worry about what anybody else is going to do. The best way to
> predict the future is to invent it." - Alan Kay
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---