in reply to Golf Challenge: all elements of an array equal


sub all_eq0 { @_{@_}=2; !((@_=%_)-2) } # 21 chars but wrong as per MeowChow sub all_eq1 { local%_; @_{@_}=2; !((@_=%_)-2) } # 29 chars sub all_eq2 { my%h; @h{@_}=2; !((@_=%h)-2) } # 26 chars
Update: Spotted the mistake in all_eq0() but MeowChow beat me to it. And then beat me some more. ;-)

John.
--

Replies are listed 'Best First'.
Re: Re: Golf Challenge: all elements of an array equal
by MeowChow (Vicar) on Jul 14, 2001 at 03:02 UTC
    Interesting method. The bad news is that it can only be used once (try princepawn's test case, setting @d = qw/a a a a a a a/). But the good news is that it can be reduced to 18 :)
    sub all_eq { (@_{@_}=1)==keys%_ }
    update: 17 chars...
    @_{@_}=0;keys%_<2
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print