[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Fwd: Please Forward: Ruby Quiz Submission

James Gray

1/20/2008 3:59:00 PM

Begin forwarded message:

> From: Yoan Blanc <yoan@dosimple.ch>
> Date: January 18, 2008 1:18:37 PM CST
> To: submission@rubyquiz.com
> Subject: Please Forward: Ruby Quiz Submission
>
> thanks.
> #!/usr/bin/ruby
> # author: Yoan Blanc <yoan at dosimple.ch>
> # revision: 20080118
>
> text = STDIN.read
>
> (text.length/2).downto 1 do |l|
> match = Regexp.new("(.{#{l}})\\1").match(text)
> if match
> puts text[match.offset(1)[0]..(match.offset(1)[1]-1)]
> break
> end
> end


1 Answer

Yoan Blanc

1/20/2008 7:52:00 PM

0

James Gray wrote:
> Begin forwarded message:
>
>> From: Yoan Blanc <yoan@dosimple.ch>
>> Date: January 18, 2008 1:18:37 PM CST
>> To: submission@rubyquiz.com
>> Subject: Please Forward: Ruby Quiz Submission
>>
>> thanks.
>> #!/usr/bin/ruby
>> # author: Yoan Blanc <yoan at dosimple.ch>
>> # revision: 20080118
>>
>> text = STDIN.read
>>
>> (text.length/2).downto 1 do |l|
>> match = Regexp.new("(.{#{l}})\\1").match(text)
while fail with text longer than (1 << 15)-1 which is the maximum string
a quantifier can handle.
>> if match
>> puts text[match.offset(1)[0]..(match.offset(1)[1]-1)]
>> break
>> end
>> end
>
>