Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Re: Golfing the day of Christmas

by jynx (Priest)
on Dec 14, 2001 at 06:45 UTC ( #131888=note: print w/replies, xml ) Need Help??

in reply to Re: Golfing the day of Christmas
in thread Christmas Coding Blues

This has a Golf Style Question attached to it...

Your answer can be trimmed down to 47 characters:

sub f { #23456789_123456789_123456789_123456789_123456789_12 $b+=$_%400?$_%100?$_%4?1:2:1:2for 1..pop;$b%7+1 }
But this begs the question, should it be immediately reusable? My guess is yes, in which case this is a non-answer. The problem is that $b doesn't get reinitialized at the start of the sub so you have to either zero it or undef it in between every call.

It returns correctly the first time, but incorrectly after that; is this ok for a golf? Or should it return correctly every time?


Replies are listed 'Best First'.
Re: Re: Re: Golfing the day of Christmas
by Sidhekin (Priest) on Dec 14, 2001 at 18:46 UTC

    jynx, your sub does not even return the correct answer the first time, if $b has been set elsewhere -- you rely on it to be numerically zero initially. Moreover, you will get a 7, not a 0, for Sundays ... so on the whole, I can't say I like it.

    That is not to say my answer cannot be trimmed down. Indeed, I just did. And just so as not to leave your suggestion as the best (sorry; I really don't like it), I trimmed it to 46 chars:

    sub f { # 1 2 3 4 5 #234567890#234567890#234567890#234567890#234567890#23 $b+=!($_%4||/00$/&&$_%400)for 0..($b=pop);$b%7 }
    Comparing that to my first suggestion ... can you tell I really like the ternary operator? ;-)

    The Sidhekin
    print "Just another Perl ${\(trickster and hacker)},"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://131888]
[ambrus]: You can actually get a lot of useful cheap really almost new products that way, with only a little risk of scams.
[ambrus]: That's what some of the "Black Friday" sales are about.
[Corion]: ambrus: Well, usually, these people don't have in their description "mail me at dodgy_reseller # g m a i l | co m" , replace the "#" by "@" :)
[Corion]: Oh, and the "o" in "com" is a zero
choroba orders a camera from Ole Scæmmer
[ambrus]: Corion: ah. that's different. the ones I mean are selling at reputable sites like ebay that usually filters scammers out pretty quickly (as well as filters a lot of legitimate users who then get annoyed that the biggest providers exclude them)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2017-11-21 15:04 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (304 votes). Check out past polls.