Archive for November 16th, 2012

Joey deVilla has a blog?

Friday, November 16th, 2012

I mean, other than “The Adventures of Accordian Guy in the Twenty-First Century“?

Yes, yes he does.

I ran across this on the Y Combinator Twitter yesterday, and thought I’d give FizzBuzz a shot. I’d estimate it took me just under 30 minutes to get the code you see here, which I believe “works”. Part of that time was taken up with assisting one of my cow orkers with a problem, though. An embarrassingly large chunk of that time was taken up by my having to look up the Perl syntax for “for”, “if”, and the modulo operator. I’m a bit rusty; the last time I wrote substantial Perl code was about a year ago (a Perl script that parses CSV data from a file and imports it into a SQL database).

Anyway, code:


#!/usr/bin/perl
for ($index = 1; $index < 101; $index++)
{
$div_by_3 = 0;
$div_by_5 = 0;
if ($index % 3 == 0) {
$div_by_3 = 1;
}
if ($index % 5 == 0) {
$div_by_5 = 1;
}
if ($div_by_3 == 1 && $div_by_5 == 1 ) {
printf "FizzBuzz\n";
} else {
if ($div_by_3 == 1) {
printf "Fizz\n";
} else {
if ($div_by_5 ==1){
printf "Buzz\n";
} else {
printf "$index\n";
}
}
}
}

As always, when I put stuff like this up, I welcome criticism or comment on how I could have done it better (or, in this case, “right” if I did it wrong). The way I see it, I can’t get any better if I don’t solicit and accept criticism.

(Followup from deVilla here.)

Edited to add: I was going to upload a Python version that I wrote in (about) 20 minutes (I think). I keep planning to sit down and learn Python, but then somebody calls and wants to go riding bikes or whatever…anyway, I couldn’t paste that here and have it come out the way I wanted to, so I’ve uploaded it here. (I had to change the extension from “.py” to “.txt” because WordPress didn’t like “.py”.)

Land of the free and home of the brave.

Friday, November 16th, 2012

I intended to make note of this earlier in the week, but it got past me:

LAT article about what it’s like sailing on board the tall ship “Bill of Rights”.

I find this worthy of note for two reasons:

  1. I like ships. Especially tall ships. So sue me.
  2. You may, or may not, remember this, but the “Bill of Rights” is the tall ship that was accidentally shelled by the “Amazing Grace” back in September. This incident, by the way, goes unmentioned in the LAT article.

(Subject line hattip: probably a lot of things, but this in particular is what I had in mind. I get that song stuck in my head every so often.)