Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Re: Shortest -return index of element in array- sub

by mr_mischief (Monsignor)
on Apr 04, 2001 at 06:19 UTC ( #69529=note: print w/replies, xml ) Need Help??

in reply to Re: Shortest -return index of element in array- sub
in thread Shortest -return index of element in array- sub

Darn. This is the route I went, too.
Just a slight bit of difference.
I really need to read all the posts before taking a challenge mentioned in the first one. ;-)

sub indexArray2 { while(@_){$_[0] eq pop && return @_-1} }

Replies are listed 'Best First'.
Re: Re: Re: Shortest -return index of element in array- sub
by mr_mischief (Monsignor) on Apr 04, 2001 at 08:10 UTC
    Now that I've taken a closer look, this is the shortest iterative version I could find (and also the shortest I could make it and have it run under strictures and warnings, although those aren't really prerequisites in golf):
    sub indexArray3{ 1while$_[0]ne pop;$#_ }
    I'd say that's pretty obfuscated, too. It can be done in a couple fewer characters recursively, if you use a one-character subroutine name and eliminate any unnecessary whitespace. I'd like to know hoe to do it in fewer iteratively, but I just can't figure anything out. Please point it out to me if there's a way.

    Chris Stith

        Apology accepted. In golf, I like to play with what the parser recognizes with whitespace and without. I'll try to credit other people from now on when I use their ideas. I thought the thread was short enough that it would be obvious where the idea was from. I don't intend to steal ideas, just borrow. I'll make it more clear that's what I'm doing. BTW, I'm not fond of trolls, either. You can find me remarking on such osts over on clpmisc quite a bit. Come to think of it, you can find me on clpmisc quite a bit in general. Chris BTW, here's my first JAPh, just so there'll be some code in my node. Comments welcome.
        $z = int(rand(1000)+1); $y = 'reverse ' x $z; eval eval qq{$y "@{['\"n\\\\.rekcaH','lreP','rehtonA','tsuJ\"','tnirp' +]}"}

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2018-08-20 18:29 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (193 votes). Check out past polls.