Please Forward: Ruby Quiz Submission

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

···

Begin forwarded message:

James Gray wrote:

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.

···

Begin forwarded message:

    if match
        puts text[match.offset(1)[0]..(match.offset(1)[1]-1)]
        break
    end
end