Skip to main content
12 events
when toggle format what by license comment
Apr 11, 2019 at 7:04 comment added David Aldridge Lovely stuff. Can I suggest instead of something like !(1..10).any? {...} that the OP use (1..10).none? {...}.
Jul 27, 2014 at 22:32 vote accept user2609980
May 29, 2014 at 13:14 comment added Uri Agassi @user2609980 - glad to be of service :-)
May 29, 2014 at 13:08 comment added user2609980 Thanks once again :) My Ruby code improved a lot because of your answer and I keep coming back to it.
Apr 21, 2014 at 10:06 comment added user2609980 @CarySwoveland I am indeed very happy with the answer :-).
Apr 20, 2014 at 18:24 comment added Cary Swoveland user2609980, I'm surprised at the difference in execution times, but I'd pay no heed to that at this stage of your Ruby education. Uri has covered a wide swath of ground in his answer, acquainting you with typical Ruby coding style, the addition of a method to an existing Ruby class (prime?), the use of powerful enumerators map, product, permutation, any? and take_while from the Enumerable module, and up_to from the Integer class, and Ruby's new lazy operator. He has also nicely explained his reasons for coding it the way he has. Great answer, Uri.
Apr 20, 2014 at 18:08 comment added Uri Agassi @user2609980 - yes, apparently lazy add a lot of overhead... see my update
Apr 20, 2014 at 18:07 history edited Uri Agassi CC BY-SA 3.0
don't be lazy...
Apr 20, 2014 at 14:58 comment added user2609980 I like your code better, but it takes 130 seconds, while the original code takes 10. The prime function is a beauty. I suspect that the count_quadratic_formula_primes method is slow.
Apr 20, 2014 at 7:37 comment added gaussblurinc also, you can inject your a*b :)
Apr 20, 2014 at 7:31 history edited Uri Agassi CC BY-SA 3.0
added 169 characters in body
Apr 20, 2014 at 7:02 history answered Uri Agassi CC BY-SA 3.0