Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread qznc
On Wednesday, 30 October 2013 at 18:56:42 UTC, Zeke wrote: On Wednesday, 30 October 2013 at 14:17:22 UTC, qznc wrote: Why do you want to find the exact prime first? Just check against sqrt(num) in the loop. auto upper = cast(ulong)sqrt(cast(double)num)) + 1; foreach(ulong prime; primes) { if

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread Zeke
On Wednesday, 30 October 2013 at 06:10:59 UTC, Ali Çehreli wrote: On 10/29/2013 11:04 PM, Zeke wrote: lowerBound and friends are related: http://dlang.org/phobos/std_range.html#.lowerBound Ali lowerBound returns a range with the last value being the sqrt, so I can't directly iterate over

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread Zeke
On Wednesday, 30 October 2013 at 14:17:22 UTC, qznc wrote: Why do you want to find the exact prime first? Just check against sqrt(num) in the loop. auto upper = cast(ulong)sqrt(cast(double)num)) + 1; foreach(ulong prime; primes) { if (prime > upper) return true; if (num % prime == 0) return

Re: Looking for something similar to Python's bisect_right

2013-10-30 Thread qznc
On Wednesday, 30 October 2013 at 06:04:36 UTC, Zeke wrote: Hello, I'm on day 2 of learning D. I've learned C, C++, Java, Python, Ruby in University, but I wanted to broaden my palette by picking up D. This project is a basic implementation of Project Euler problem 10. I build an array of prim

Re: Looking for something similar to Python's bisect_right

2013-10-29 Thread Ali Çehreli
On 10/29/2013 11:04 PM, Zeke wrote: lowerBound and friends are related: http://dlang.org/phobos/std_range.html#.lowerBound Ali

Looking for something similar to Python's bisect_right

2013-10-29 Thread Zeke
Hello, I'm on day 2 of learning D. I've learned C, C++, Java, Python, Ruby in University, but I wanted to broaden my palette by picking up D. This project is a basic implementation of Project Euler problem 10. I build an array of primes, and for each new test number I check if the test is div