Ruby Quiz Contest Winner!

Ross B. 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 G. II

On 5/8/06, James Edward G. II [email protected] wrote:

Ross B. 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.

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

On 5/8/06, James Edward G. II [email protected] wrote:

Ross B. 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

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

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

Ross B. wrote this week’s quiz (the winner)… and next week’s
too. :wink:

James Edward G. II

On 5/8/06, Logan C. [email protected] wrote:

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

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 Tue, 2006-05-09 at 04:01 +0900, James Edward G. II wrote:

Ross B. 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.)

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 Q…

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©
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 May 9, 2006, at 4:23 AM, Ross B. wrote:

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

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 Q… It’s that simple.

James Edward G. II