Re: help with prime pairs code

2025-02-21 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 19 February 2025 at 23:58:09 UTC, Salih Dincer wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: I'm converting Ruby code to D and am running into issues. Would appreciate what needs to be done to get it to compile/run correctly. I removed 1 line in your co

Re: help with prime pairs code

2025-02-19 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: I'm converting Ruby code to D and am running into issues. Would appreciate what needs to be done to get it to compile/run correctly. First of all, I see that you don't use reserve() at all in arrays. Since I work on a mobile pla

Re: help with prime pairs code

2025-02-19 Thread Sergey via Digitalmars-d-learn
On Wednesday, 19 February 2025 at 02:25:03 UTC, Salih Dincer wrote: have much time right now, I only saw 1 improvement. Below the GCD filter will give the same list (lhr[]). SDB@79 It is giving different result

Re: help with prime pairs code

2025-02-18 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 18 February 2025 at 22:45:39 UTC, Jabari Zakiya wrote: I'm bringing attention to this issue as it might improve D. Known issue with upstream, try one of mine data structures https://github.com/opendlang/d/blob/main/source/odc/datastructures.d

Re: help with prime pairs code

2025-02-18 Thread Jabari Zakiya via Digitalmars-d-learn
// convert lhr_mults vals > n/2 to their lhr complements n-r, // store them, those < n/2, in lhr_del; it now holds non-pcp lhr vals auto lhr_del = lhr_mults.map!((r_del) => r_del > ndiv2 ? n - r_del : r_del).array; lhr_del.sort!("a < b"); lhr = setDifference(lhr, l

Re: help with prime pairs code

2025-02-08 Thread Jabari Zakiya via Digitalmars-d-learn
On Wednesday, 5 February 2025 at 21:24:51 UTC, Jabari Zakiya wrote: On Tuesday, 4 February 2025 at 17:17:42 UTC, Jabari Zakiya wrote: On Monday, 3 February 2025 at 04:59:43 UTC, monkyyy wrote: On Monday, 3 February 2025 at 04:15:09 UTC, Jabari Zakiya wrote: I translated this Ruby code: FY

Re: help with prime pairs code

2025-02-05 Thread Jabari Zakiya via Digitalmars-d-learn
On Tuesday, 4 February 2025 at 17:17:42 UTC, Jabari Zakiya wrote: On Monday, 3 February 2025 at 04:59:43 UTC, monkyyy wrote: On Monday, 3 February 2025 at 04:15:09 UTC, Jabari Zakiya wrote: I translated this Ruby code: FYI. This code finds all the prime pairs that sum to n for all even in

Re: help with prime pairs code

2025-02-04 Thread Jabari Zakiya via Digitalmars-d-learn
On Monday, 3 February 2025 at 04:59:43 UTC, monkyyy wrote: On Monday, 3 February 2025 at 04:15:09 UTC, Jabari Zakiya wrote: I translated this Ruby code: FYI. This code finds all the prime pairs that sum to n for all even integers n > 2. It (Ruby code) is included in a paper I just released

Re: help with prime pairs code

2025-02-02 Thread monkyyy via Digitalmars-d-learn
On Monday, 3 February 2025 at 04:15:09 UTC, Jabari Zakiya wrote: I translated this Ruby code: To this D code. It works, seems fast, can it be done shorter, faster, more idiomatic? translated code isnt going to be idiomatic ever; just state what you want done

Re: help with prime pairs code

2025-02-02 Thread Sergey via Digitalmars-d-learn
On Sunday, 2 February 2025 at 22:40:41 UTC, Jabari Zakiya wrote: I am really impressed! D is phenomenally memory efficient with this code. I just ran the D code for some really large n values. On my older Lenovo Legion 5, using Linux (June 2024) w/16GB I was able to go up to n = 1,000,000, a

Re: help with prime pairs code

2025-02-02 Thread Sergey via Digitalmars-d-learn
On Sunday, 2 February 2025 at 03:22:00 UTC, Jabari Zakiya wrote: The D version is way slower, because of the array operations. For an input of 100 (1M): D: 12+ secs; Crystal: 0.036 secs. First of fall make sure you are using LDC or GDC compiler. Second step is to add proper flags for optim

Re: help with prime pairs code

2025-02-01 Thread Jabari Zakiya via Digitalmars-d-learn
On Sunday, 2 February 2025 at 01:39:34 UTC, user1234 wrote: On Sunday, 2 February 2025 at 01:12:59 UTC, user1234 wrote: On Saturday, 1 February 2025 at 21:56:23 UTC, Jabari Zakiya wrote: On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Ja

Re: help with prime pairs code

2025-02-01 Thread user1234 via Digitalmars-d-learn
On Sunday, 2 February 2025 at 01:12:59 UTC, user1234 wrote: On Saturday, 1 February 2025 at 21:56:23 UTC, Jabari Zakiya wrote: On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: [...] A first draft of the translation

Re: help with prime pairs code

2025-02-01 Thread user1234 via Digitalmars-d-learn
On Saturday, 1 February 2025 at 21:56:23 UTC, Jabari Zakiya wrote: On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: [...] A first draft of the translation, not very idiomatic D code: ```d module prime_pairs; import

Re: help with prime pairs code

2025-02-01 Thread Jabari Zakiya via Digitalmars-d-learn
On Saturday, 1 February 2025 at 00:21:22 UTC, user1234 wrote: On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: [...] A first draft of the translation, not very idiomatic D code: ```d module prime_pairs; import std; [...] Thank you very much! As you can see, D is not my pri

Re: help with prime pairs code

2025-01-31 Thread user1234 via Digitalmars-d-learn
On Friday, 31 January 2025 at 20:05:54 UTC, Jabari Zakiya wrote: I'm converting Ruby code to D and am running into issues. Would appreciate what needs to be done to get it to compile/run correctly. Here's the Ruby code: [...] A first draft of the translation, not very idiomatic D code: ```

help with prime pairs code

2025-01-31 Thread Jabari Zakiya via Digitalmars-d-learn
I'm converting Ruby code to D and am running into issues. Would appreciate what needs to be done to get it to compile/run correctly. Here's the Ruby code: ``` # Enable YJIT if using CRuby >= 3.3" RubyVM::YJIT.enable if RUBY_ENGINE == "ruby" and RUBY_VERSION.to_f >= 3.3 def prime_pairs_lohi(