From: Daniel Martin Date: 2007-06-02T23:04:13+09:00 Subject: Re: [QUIZ] FizzBuzz (#126) dblack@wobblini.net writes: > I'm afraid I'm stuck on 71. Is it OK to post solutions here at this > stage? According to the rules posted, we need to wait 48 hours from the initial posting, which will in my timezone (US Eastern) be at 8:28 tomorrow morning. At this point, the only things fair to post (based on past quizzes) would be: - sample output - unit tests - speed measurements You'd have to be careful, though, to construct a unit test that does not itself contain a quiz solution. I guess it's kosher to post this test program, written in sh: #! /bin/sh RUBYSCRIPT=$1 if [ `ruby "$RUBYSCRIPT" | wc -l` -ne 100 ]; then echo "Fail linecount"; exit 1 fi ruby "$RUBYSCRIPT" | \ egrep -v '^([0-9]+|Fizz|Buzz|FizzBuzz)$' > /dev/null if [ $? -eq 0 ]; then echo "Fail content"; exit 1 fi # now a few spotchecks spotcheck() { ruby "$RUBYSCRIPT" | nl | grep "^ *$1.$2\$" > /dev/null if [ $? -ne 0 ]; then echo "Fail $*"; exit 1 fi } spotcheck 1 1 spotcheck 3 Fizz spotcheck 5 Buzz spotcheck 15 FizzBuzz spotcheck 23 23 spotcheck 90 FizzBuzz spotcheck 97 97 spotcheck 98 98 spotcheck 99 Fizz spotcheck 100 Buzz echo Passed exit 0 -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.to_a.last ) puts "s=%q(#{s})",s.to_a.last