It did tell me that a million was a prime number though...
Due to golfing it, it doesn't handle the very last number correctly.
I don't understand those at all really,
They both work in essentially the same way. The first one creates a string of $limit '1's. It then uses a regex to scan the string substituting '0's for '1's, for all the multiples. It then scans the string, incrementing a counter, looking for the remaining '1's and prints out the counter when it finds a '1'. It just uses the big string as a tally stick and 'crosses off' all the multiples.
The second one does the same thing, but uses vec, and bits instead of bytes, to represent the tally stick.
By avoiding building big lists/arrays, it allows you to go 30/250 or so times higher.
If you're not golfing, it is easy to omit the even bytes/bits and therebye double the range again.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.