Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?

jynx


Comment on Re: Re: Golfing the day of Christmas
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://131888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-28 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls