[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Golf (7, er 16 strokes is par!)



On Mon, 1 May 2000, Dean Hudson wrote:

> Anyone have any solutions that do the same thing but work with 0? I've got
> a solution that works with 0 but it's 16 characters. I'd like to see
> something shorter, if possible.

Due to the underwhelming response, I'll post the solution with the hopes
that it attracts golfers:

($_^$_-1)-2*$_+1

which is based on:

(n xor n-1)-(2n-1)

which gives the correct answer for zero. Can anyone Perl or bit-logic away
any of the characters? It sits at 16 which is more than twice as long as
the K&R solution.

(Credit for the logic goes to Jacob Bridge, CC'd on this message.)

dean.
--
my $email = qr{ dean(h)?@(?(1)verio\.net    # @ work if h
                            | ero\.com) }x; # other


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe