Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is my very first golf attempt, and I know it's pretty bad, but here it goes:

Well, it does return duplicates (2 2 5 5 7 7) since I use a hash, but I didn't see anything in the problem that said you couldn't. I count 77 chars (see update). (Note: that is excluding the new-lines, I ran it with out them, but I posted new lines here to be more pleasing to the eye, also, it is excluding the sub a { and the end } parts).

sub a { @a{2..$_[0]}=2..$_[0]; for$b(%a){!($b%$_)&&$b!=$_&&delete@a{$b}for(%a)} %a }
One last note, since this is my first golf, I would very much appreciate any suggestions or improvements to my code. I realize I took a very straight forward approach to this solution, but that is how I think.

Update:Took it down to 73 chars. I took out one set of un-needed parenentheses and two un-needed semicolons.

Note:If you put keys before the %a it takes away the problem of repeats, but it brings me back to where I started with 77 chars.

The 15 year old, freshman programmer,
Stephen Rawls

In reply to Re: (Golf): Sieve of Eratosthenes by srawls
in thread (Golf): Sieve of Eratosthenes by tilly

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (8)
    As of 2018-06-22 00:14 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (120 votes). Check out past polls.