Morendil comments on Open Thread: March 2010, part 2 - Less Wrong

4 Post author: RobinZ 11 March 2010 05:25PM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (334)

You are viewing a single comment's thread. Show more comments above.

Comment author: Morendil 18 March 2010 06:35:54PM *  0 points [-]

Thanks. I was mostly kidding, but I appreciate the extra perspective.

(Signalling my own affiliation as a true geek, I actually attempted to download a LOLCODE interpreter and run it on the above, but the ones I could get my hands on seem to be broken. I would upvote it if I could run it, and it gave the right answer.)

Comment author: AdeleneDawner 18 March 2010 06:49:26PM *  2 points [-]

integer var

while(1)

{

++var

if (var % 15 == 0)

output "FizzBuz"

else if (var % 3 == 0)

output "Fizz"

else if (var % 5 ==0)

output "Buzz"

else

output var

if !(var<100)

return

}

Looks right to me, though I wound up reformatting the loop a little. That's most likely a result of me being in the habit of using for loops for everything, and forgetting the proper formatting for other kinds, rather than being an actual flaw in the code - I'm willing to give bogus the benefit of the doubt about it, in any case.

Comment author: gregconen 18 March 2010 07:14:20PM 1 point [-]

Pretty much. Both you and bogus apparently forget to put an initial value into var (unless your language of choice automatically initializes them as 0).

Using while(1) with a conditional return is a little bizarre, when you can just go while(var<100).

Of course, my own draft used if(var % 3 == 0 && var % 5 == 0) instead of the more reasonable x%15.

Comment author: AdeleneDawner 18 March 2010 07:25:56PM 1 point [-]

Pretty much. Both you and bogus apparently forget to put an initial value into var (unless your language of choice automatically initializes them as 0).

Mine does, but I'm aware that it's good coding practice to specify anyway. I was maintaining his choice.

Using while(1) with a conditional return is a little bizarre, when you can just go while(var<100).

Yep, but I don't remember how else to signify an intrinsically infinite loop, and bogus' code seems to use an explicit return (which I wanted to keep for accuracy's sake) rather than checking the variable as part of the loop.

My method of choice would be for(var=0; var<100; ++var){} (using LSL format), which skips both explicitly returning and explicitly incrementing the variable.