Page 4 of 4
Posted: Sat Aug 02, 2014 7:13 pm
by GORDON
My personal assessment of my own code, once I had the eyes to make that kind of analysis, is that my code tends to be more utilitarian than artistic. I've seen things I have done redone now and again to be prettier, but not with any better functionality.
Posted: Mon Aug 04, 2014 4:55 pm
by TPRJones
Not sure of the exact syntax of the language you are using, but I think this would be close to maximum efficiency (please excuse my pseudocode):
public function FizzBuzzLoop(int i)
{
str thistime = null;
if (i % 3 == 0) { thistime = "Fizz"; }
if (i % 5 == 0) { thistime = thistime + "Buzz"; }
if (thistime == null) { Console.WriteLine(i.ToString()); }
else { Console.WriteLine(thistime); }
if (i < 101) { FizzBuzzLoop(i+1); }
}
One less evaluation and it swaps in recursion in place of a while loop.
Posted: Mon Aug 04, 2014 5:50 pm
by Malcolm
GORDON wrote:My personal assessment of my own code, once I had the eyes to make that kind of analysis, is that my code tends to be more utilitarian than artistic. I've seen things I have done redone now and again to be prettier, but not with any better functionality.
After debugging other people's code enough, I place readability on a very high level.
Posted: Mon Aug 04, 2014 6:32 pm
by TheCatt
TPRJones wrote:Not sure of the exact syntax of the language you are using, but I think this would be close to maximum efficiency (please excuse my pseudocode):
public function FizzBuzzLoop(int i)
{
str thistime = null;
if (i % 3 == 0) { thistime = "Fizz"; }
if (i % 5 == 0) { thistime = thistime + "Buzz"; }
if (thistime == null) { Console.WriteLine(i.ToString()); }
else { Console.WriteLine(thistime); }
if (i < 101) { FizzBuzzLoop(i+1); }
}
One less evaluation and it swaps in recursion in place of a while loop.
The recursion is unnecessary. And inefficient, as you will be increasing your memory allocation for the variables you create with each call, that won't go out of scope since your calls are now nested.
Posted: Mon Aug 04, 2014 6:37 pm
by TPRJones
Oh. Well, nevermind then.
Need a better language. Recursion is too awesome to sacrifice to bad memory management.
Posted: Mon Aug 04, 2014 6:50 pm
by TheCatt
TPRJones wrote:Oh. Well, nevermind then.
Need a better language. Recursion is too awesome to sacrifice to bad memory management.
I'm not sure what language that would be possible in.
That Fibonacci solution for recursion is nice.
Posted: Mon Aug 04, 2014 7:03 pm
by thibodeaux
TPRJones wrote:Oh. Well, nevermind then.
Need a better language. Recursion is too awesome to sacrifice to bad memory management.
Some LISPs have "tail recursion" which can be implemented as a GOTO. No memory problems.
Posted: Mon Aug 04, 2014 7:22 pm
by TPRJones
I could do it in Forth. Or declare the variables as globals instead (Pascal, Fortran, many others), although that's bad for other reasons.
Posted: Mon Aug 04, 2014 7:28 pm
by Malcolm
TheCatt wrote:TPRJones wrote:Oh. Well, nevermind then.
Need a better language. Recursion is too awesome to sacrifice to bad memory management.
I'm not sure what language that would be possible in.
That Fibonacci solution for recursion is nice.
Inefficient as hell, too.
Some LISPs have "tail recursion" which can be implemented as a GOTO. No memory problems.
TPR's solution looks tail-recursive (iterative). Run-time is still big-omega(N). In fact, outside of butchering the logic inside the function, it'd be hard to make this recursive in a dangerous way. It's the opposite of the Fibonacci, which is (relatively) difficult to do non-recursively. Someone today, with some hints, finally got the good solution. First one this round.
Edited By Malcolm on 1407195179
Posted: Fri Aug 08, 2014 1:04 pm
by GORDON
So is there some rule in fizzbuzz that says I can't just write a single line of code: print " 1 2 fizz 4 buzz..." Etc?
I mean, as long as we are thinking outside the box. Did anyone say it had to be overly complicated?
Posted: Fri Aug 08, 2014 1:06 pm
by Malcolm
GORDON wrote:So is there some rule in fizzbuzz that says I can't just write a single line of code: print " 1 2 fizz 4 buzz..." Etc?
I mean, as long as we are thinking outside the box. Did anyone say it had to be overly complicated?
Works fine until you print from 1 to N.
EDIT: Contractor managed to renege on his acceptance. Fucking recruiting firms and their visa bullshit.
Edited By Malcolm on 1407517648