I have programmed in a few languages extensively in my life, though now I primarly use Ruby.

I just found out about Nim literlly 3 weeks ago now (mid July 2017) after reading this article: Nim for the discerning Rubyist http://www.rubyflow.com/p/1j08ef-nim-for-the-discerning-rubyist

I primarly use Ruby to apply to math/science problems/projects because it's so easy to programm in, and it allows me to think about how to solve problems without worrying about how to code it. I've also played around with Crystal (aka Ruby on steroids) but it's still young, and doesn't let me (currently) do what I want, or without a lot of hassles.

However Nim looks promising, especially it's parallel programing features (if real and not brain destroying).

So here's a request, and maybe a challenge, to the Nimers (Nimrods, Nimists, Nimsters,..) gurus.

I developed a prime sieve called the Sieve of Zakiya (SoZ), and it's companion the Segmented Sieve of Zakiya (SSoZ).

I wrote a paper, The Segmented Sieve of Zakiya (SSoZ) which describes its mathematical foundations and algorithm, and provides a working cpp implementation at the end of the paper (compiled, run, and verified). It's a relatively short program.

Here's a link to read and download the paper:


My request/challenge is for someone(s) who are good at Nim to translate the code into idiomatic Nim, to demonstrate the best way to do this algorithm in Nim. Extra points if someone can do a parallel version of the algorithm, which I attempted to do using OpemMP, but what I did didnt' seem to make the code faster than the serial version.

I know this may be a lot to ask, but I learn best from code doing problems I understand, like the Rosetta Code benchmarks, but those are too short to learn enough for this algorithm.

Ultimately, I'd like to publish to results of benchmarks in different languages doing the SSoZ in an updated paper.

If anyone has any question, I'd be pleased to answer them as best I can.

Thanks in advance.


2017-08-07 04:45:13

Honestly, this sounds like an interesting little project to bang out. However, I must admit that I am a humble Web Developer and, by extension, am not well versed in mathematics.

The best I could do is translate your C code in the linked document into Nim and maybe make a few small changes. However, without a deeper understanding of your algorithm, I doubt I would be able to optimize it in any meaningful way. It seems like your paper does a good job explaining the concepts behind the algorithm, but I do not have enough free time at the moment to work on this as I am approaching a deadline to launch a web application.

My suggestion is for you to possibly try and implement the algorithm in Nim yourself. You will find it to be surprisingly simple, I'm sure. If you then link to the repository here, we can help you by reviewing the code and making pull requests.

2017-08-08 15:37:29

Thanks. I'm in the process of learning enough Nim to take on this effort. However, I would do what you were thinking, and first try a comparable direct C++ to Nim translation, just to get something to work. But it's going to be some time (with my time/learning curve constraints) to create something workable.

I'm hoping someone who's really fluent in Nim, and who thinks in Nim, can perform the algorithm in a Nimby way that best showcases its capabilites. Once you get your head around the algorithm (and/or math) it shouldn't be too hard to understand what the C++ code is doing. Then someone versed in Nim can structure the alogrithm, particularly a true parallel processing version, in an efficient manner.

2017-08-08 19:25:44
Can you put the paper on a link that is not behind a paywall? I am normally pretty trained to port from different languages to different languages, but from the paper I can't do copy paste at all. 2017-08-08 19:36:29

The link I provided in my first post allows you to read/download it free from my Scribd site. Here it is again.


I've tested it many times, and there is no filter/paywall to get around. Let me know if this doesn't work and I'll provide another method to get to it.

2017-08-08 20:55:48

Sounds interesting, I might try doing a direct port from cpp to nim when I get some free time.

Btw, download is indeed behind a paywall (looks like scribd offers a month free but after that it's paid). Reading is free though.

Copy pasting from the pdf is impossible, as latex or whatever mangles the symbols, but I found a gist here

Also found this link in the references https://www.4shared.com/dir/TcMrUvTB/sharing.html but it won't let me download anything.

I'd suggest setting up a github pages website with an html version (pandoc or similar can convert most formats to html) or at least some kind of git repo with the code, as it's free and most people here are used to cloning things to look at them on their pc (at least I am).

2017-08-09 07:05:35

OK, thanks for the feedback on your problems downloading the paper.

Can you tell me what platform you are using, and what country you're accessing from?

I see from my Scribd stats that the paper is being downloaded so it appears to be working for others.

I'll look at putting the paper up on github, though.

2017-08-09 15:39:41