Ruby Quiz Contest Winner!

Ross Bamford has submitted a quiz that exceeded the mark I said I would give a book to. Way to go Ross! (Thanks to everyone else who entered as well.)

Ross, if you will send me your address off-list, I'll get a book on its way.

James Edward Gray II

Will his quiz be the next? You have defintely piqued my curiousity.

···

On 5/8/06, James Edward Gray II <james@grayproductions.net> wrote:

Ross Bamford has submitted a quiz that exceeded the mark I said I
would give a book to.

Wow - I never win _anything_ :slight_smile: Part of me wants to say I couldn't take
the prize, to let the contest run, but another part of me (the part
that's wanted this book for ages and still doesn't have it ;)) just
can't do that... Thanks to everyone who coded up solutions, and big
thanks to James for the contest, and for running the Ruby Quiz.

Here's my own basic solution, modified slightly as we refined the
problem:

#!/usr/local/bin/ruby
def check_parens(s, parens = '(){}')
  stack =
  s = s.gsub(/\\[#{Regexp.escape(parens)}]/, '')
  s.split(//).each_with_index do |c,i|
    if tp = parens.index(c)
      if tp == (pg_start = (tp / 2) * 2)
        # opening paren
        stack << [c,i]
      else
        # closing paren
        if (stack.last || ).first == parens[pg_start,1]
          stack.pop
        else
          stack << [c,i]
          break
        end
      end
    end
  end
  stack
end

def balanced_and_valid?(s, parens = '(){}')
  !!if check_parens(s,parens).empty?
    rx = /#{parens.scan(/../).map { |e| Regexp.escape(e) }.join('|')}/
    true unless s =~ rx
  end
end

if $0 == __FILE__
  raise ArgumentError, 'No input', unless brackets = ARGV.first
  exit(balanced_and_valid?(brackets) ? 0 : 1)
end

···

On Tue, 2006-05-09 at 04:01 +0900, James Edward Gray II wrote:

Ross Bamford has submitted a quiz that exceeded the mark I said I
would give a book to. Way to go Ross! (Thanks to everyone else who
entered as well.)

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk

Um, for him to have won, his quiz would have had to have already occured

···

On May 8, 2006, at 3:54 PM, Belorion wrote:

On 5/8/06, James Edward Gray II <james@grayproductions.net> wrote:

Ross Bamford has submitted a quiz that exceeded the mark I said I
would give a book to.

Will his quiz be the next? You have defintely piqued my curiousity.

I too have enjoyed the contest and it just so happens that I have another book here... Let's go one more round!

For those joining us late here's the deal: submit a quiz that grabs 15 or more solutions and I will mail you a signed copy of Best of Ruby Quiz. It's that simple.

James Edward Gray II

···

On May 9, 2006, at 4:23 AM, Ross Bamford wrote:

Part of me wants to say I couldn't take
the prize, to let the contest run...

My apologies, I've been out of the RubyTalk loop for a couple of weeks.
It's like walking into the middle of a movie but not knowing you've missed
the first half ;).

···

On 5/8/06, Logan Capaldo <logancapaldo@gmail.com> wrote:

Um, for him to have won, his quiz would have had to have already occured

Ross Bamford wrote this week's quiz (the winner)... and next week's too. :wink:

James Edward Gray II

···

On May 8, 2006, at 3:03 PM, Logan Capaldo wrote:

On May 8, 2006, at 3:54 PM, Belorion wrote:

On 5/8/06, James Edward Gray II <james@grayproductions.net> wrote:

Ross Bamford has submitted a quiz that exceeded the mark I said I
would give a book to.

Will his quiz be the next? You have defintely piqued my curiousity.

Um, for him to have won, his quiz would have had to have already occured