Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Golf: 3 hole golf game

by etcshadow (Priest)
on Nov 17, 2004 at 06:31 UTC ( #408322=note: print w/replies, xml ) Need Help??

in reply to Golf: 3 hole golf game 103 strokes 37 strokes 37 strokes ------------------------ total: 177 strokes
Although my is (sadly) a complete ripoff of Tilly's... I just changed the arbitrary limit to a silly but not arbitrary one. Also, no modules for #2 or #3. :::::::::::::: @x=<>;$z=length"@x";%x=map{($x=lc)=~s/\d+/0 x($z-length$&).$&/ge;$_,$x}@x;print sort{$x{$a}cmp$x{$b}}@x :::::::::::::: :::::::::::::: @_=<>;print splice@_,rand@_,1for 1..2 :::::::::::::: :::::::::::::: print splice@_,rand@_,1for 1..(@_=<>)

Frankly, I feel that this should count as a solution to #1, but it doesn't, because perl's native arithmetic comparison is just broken on ludicrously long numbers:

:::::::::::::: :::::::::::::: print map{@$_}sort{$z=0;{$z>@$a?0:lc$$a[$z]cmp lc$$b[$z++]||$$a[$z]<=> +$$b[$z++]||redo}}map{[split/([\d\n]+)/]}<>

Oh, well. It's still longer than my cleaned-up version of Tilly's, so I guess it's no real loss.

------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re^2: Golf: 3 hole golf game
by tilly (Archbishop) on Nov 17, 2004 at 16:04 UTC
    And ripping off dragonchild's improvements on my, plus adding one improvement on your strategy we get to 94 characters:
    @x=<>;print sort{$x{$a}cmp$x{$b}}map{($x{$_}=lc)=~s/\d+/0 x(length("@x")-length$&).$&/ge;$_}@x
    Incidentally nice work on the select and shuffle problems. Marginally less efficient than my solution, but a lot shorter. (Well technically your solution is quadratic, but the quadratic bit has a small constant.)

      Was efficiency a requirement? If it was, then oops. Oh, well, I was optimizing for brevity.

      P.S. I wasn't able to inline the "@x" when I tried it (must be because I'm using a much older perl). I didn't throw in the $z="@x"; just to waste space. I was actually pretty disapointed at having to do so. Nice. I should really upgrade my perl (or at least have a more up-to-date version around).

      ------------ :Wq Not an editor command: Wq
        Brevity was indeed the requirement. I was just trying to make myself feel better. ;-)
Re^2: Golf: 3 hole golf game
by dragonchild (Archbishop) on Nov 17, 2004 at 12:59 UTC
    You can get another stroke out of by changing your elipsis to a comma. That gets you to 36.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Oh, yeah, duh. :-D

      It should be obvious that my is just a trivial modification to my I obviously didn't spend long enough converting it over. Thanks.

      ------------ :Wq Not an editor command: Wq

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-05-26 13:37 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (153 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!