TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Naive Parallel Prime Numbers Sieve in Erlang

41 点作者 old_sound超过 11 年前

2 条评论

pavanky超过 11 年前
I implemented this in python to compare this version with the semi naive version I am wrote for projecteuler problems a few years ago.<p>The semi naive version checks only the numbers of the form 6n + 1 and 6n - 1 because all other numbers (6n + 2, 6n + 3, 6n + 4, 6n) are divided by 2 or 3.<p>Here is the code: <a href="https://gist.github.com/pavanky/9053387" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;pavanky&#x2F;9053387</a><p>Here are the results:<p>&gt;$ python isprime.py<p>&gt;isprime_6k @ 100 5.08 1.54<p>&gt;isprime_sv @ 100 10.47 2.09<p>&gt;isprime_6k @ 1000 11.94 2.23<p>&gt;isprime_sv @ 1000 30.83 3.91<p>&gt;isprime_6k @ 10000 33.78 3.3<p>&gt;isprime_sv @ 10000 96.45 7.06<p>sv is the sieve version 6k is the semi naive version I mentioned. The first number is the (average) number of comparisons if the number is prime. The second number is the (average) number of comparisons if the number is not prime.<p>It looks like the sieve version is doing a much larger number of comparisons as the numbers get larger. Please let me know if I have done any mistakes in the coding. I did this fairly quickly and need more eyes to double check.
评论 #7252733 未加载
lagnarok超过 11 年前
fwiw somebody has raised an issue with the mathematical underpinning: <a href="https://github.com/videlalvaro/erlang-prime-sieve/issues/2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;videlalvaro&#x2F;erlang-prime-sieve&#x2F;issues&#x2F;2</a>
评论 #7253460 未加载