[QUIZ] FizzBuzz (#126)

R

Rick DeNatale

quoth the Ari Brown:

Mine is 8 lines (not including the shebang) two of which are 'end's. I wrote
it in probably the most obvious way, so it's certainly not 'clever' or
anything.

As I said, I wrote 6 different versions, all of them are methods on
Integer, and a (1..100).each {|i| p i.fizz_buzzn)

where n is an integer.

The most obvious method has 8 lines inside the def/end, while the
shortest has one.
 
B

Bill Kelly

From: "Ari Brown said:
Hey all, I have a quick question on this quiz:
I have a working version of it, but I just want to compare and see
what everyone else got.

How many lines do you have it written in?

I typed it in as a one-liner in IRB just out of curiosity. I figured
it was some kind of trick question, so I tried to be as non-clever as
possible.

After that I made a slightly shorter version of the one-liner just to
eliminate some duplication. But still nothing very clever. :)


Regards,

Bill
 
D

Daniel Martin

Sander Land said:
Mathematica.

Bingo.

And APL is significantly less legible than this. (Among other things,
I used ASCII there) Even J (APL's modern, ASCII-based descendant)
would be less legible than that.
 
M

Morton Goldberg

Write a program that prints the numbers from 1 to 100.
But for multiples of three print =93Fizz=94 instead of the
number and for the multiples of five print =93Buzz=94. For
numbers which are multiples of both three and five
print =93FizzBuzz=94.

I would not be surprised if this quiz produces the most submissions =20
of any quiz ever.

Regards, Morton=
 
D

Daniel Martin

Ruby Quiz said:
Write a program that prints the numbers from 1 to 100.
But for multiples of three print "Fizz" instead of the
number and for the multiples of five print "Buzz". For
numbers which are multiples of both three and five
print "FizzBuzz".

Anyone care for a friendly game of golf?
I've got this in 67 characters...
 
D

dblack

B

Brian Candler

Hi --



I'm afraid I'm stuck on 71. Is it OK to post solutions here at this
stage?

67 here too, and nothing really clever in it.

$ wc fizzbuzz.rb
0 4 67 fizzbuzz.rb
$ ruby fizzbuzz.rb | tail -5
Fizz
97
98
Fizz
Buzz
 
B

Brian Candler

Anyone care for a friendly game of golf?
I've got this in 67 characters...

Actually, I've now got 65 character or 62 characters. The 62 character
version interprets the specification literally by printing "Fizz", "Buzz" or
"FizzBuzz" *with* the double quotation marks :)
 
D

Daniel Martin

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
 
A

Ari Brown

Hey all,
my first ruby submission is coming up, and i'm pretty psyched - I'm
even cron-ing my email submission to try to be the first one in :-D

But I have a problem. In my code, I want to use case - when
statements in it to reduce line wastage. BUT I get an error when I
try to use this sample code:

case s
when s + 1 == y and s - 1 == q

anyhelp?

also, modulus is x % y, right?

thanks,
---------------------------------------------------------------|
~Ari
"I don't suffer from insanity. I enjoy every minute of it" --1337est
man alive
 
J

James Edward Gray II

Anyone care for a friendly game of golf?
I've got this in 67 characters...

Is that how you would solve it in your job interview? Just curious.

James Edward Gray II
 
D

Daniel Martin

James Edward Gray II said:
Is that how you would solve it in your job interview? Just curious.

Well, no. In a job interview I'd give the first solution I came up
with, which is quite boring. At least, initially. If explicitly
asked for different solutions, maybe. At a job interview I've alluded
to before, I was asked to write a perl one-liner that did a particular
task, and later as we had some extra time at the end of the interview,
(it was a marathon interview day, with interviews scheduled on the
hour) I spent a minute or two with the interviewer looking at ways to
play perlgolf with my solution.

Basically, trying to golf the solution is a form of joking around with
the interviewer,(*) and like anything of that nature, you do it only
when appropriate.

(*) albeit a highly geeky form of joke
 
J

Joshua Ballanco

Actually, I've now got 65 character or 62 characters. The 62 character
version interprets the specification literally by printing "Fizz",
"Buzz" or
"FizzBuzz" *with* the double quotation marks :)

I'll match your 62, but I'm still thinking that some clever tricks might
get it lower!

sh-3.2$ wc fizzbuzz.rb
0 2 62 fizzbuzz.rb
sh-3.2$ ruby fizzbuzz.rb | tail -11
"FizzBuzz"
91
92
"Fizz"
94
"Buzz"
"Fizz"
97
98
"Fizz"
"Buzz"
 
S

Sammy Larbi

Sun said:
I golf too! :)
I got to reach 56 bytes, but I highly doubt I can shave one more byte
from
it.
I can't wait for tomorrow to see how you all got such ridiculously low
numbers =)
 
T

Todd Benson

I can't wait for tomorrow to see how you all got such ridiculously low
numbers =)

I'm down to 42 chars.


Just kidding :) The best I could do was 74, and it looks crappy.

Todd
 
R

Robert Dober

I golf too! :)
I got to reach 56 bytes, but I highly doubt I can shave one more byte from
it.
We failed, just look at the achieves, I do not consider that a spoiler
because I am sure James was aware of the Ruby ML community's attempt
to get it to 56 bytes in March if I recall correctly.

And no I guess nobody would golf at a job interview unless it were for
the PGA of course.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top