SPOILER Re: SPUG: scalar swap challenge

Colin Meyer cmeyer at helvella.org
Thu Oct 9 13:39:53 CDT 2003


On Thu, Oct 09, 2003 at 11:19:44AM -0700, Tim Maher/CONSULTIX wrote:
> On Thu, Oct 09, 2003 at 10:43:33AM -0700, Colin Meyer wrote:
> 
> I was also thinking tangentially, considering a regex-based
> solution.  But really, what's the point here? WHY is it desirable
> to avoid using a temporary variable?  Presumably to minimize memory
> usage, because making a fresh entry in the symbol table alone surely
> couldn't be motivating the stinginess indicated by the goal.  (But
> the guy who was motivated to save that extra variable allocation
> must be using computers from the 80s, for this to be a practical concern;
> unless we're talking about storing all the digits of PI in one of the
> scalars that needs swapping).
> 
> And given that most solutions based on string handling would tend to
> require some additional memory usage (although I'd like to think
> the substring case would be an exception), I'm left asking why not just spend
> the extra scalar, and do the conventional swap?  If the intent of the
> question is merely to showcase different approaches, fine, but ones
> that use even more resources than the obvious variable-juggling one
> don't seem worthy of much free publicity.

I don't think there is any reason to not use a temporary variable,
especially considering the obfuscation factor. It is much more clear to
use a temp var. Unlike Lee, who likes to interview programmers with an
especially convoluted variety of this thing, I'd give a stern talking to
any programmer who I caught doing silly things like this. If I caught
them doing unnecessary obfuscation a second time, I'd fire them. After
all, programmers are a dime a dozen; they'd better behave! ;-)

Actually, I quite enjoy interviews with silly puzzles. I assume that
Lee would eschew this sort of thing in real code. It is fun (and
probably good brain exercise) to think about code puzzles, and play
with them *in a non production context*.

I'm curious about what MJD's response about using this as one of his
weekly quizzes would be. I don't follow them too closely, but I think
that he tends to favor practical solutions, whereas this puzzle is 
geared towards entirely unpractical solutions.

-Colin. 



More information about the spug-list mailing list