Skip to main content
19 events
when toggle format what by license comment
Feb 5, 2017 at 11:10 comment added kglr @Mr.Wizard, @AliHashimi looks like i should replace ReplaceList with Replace.
Feb 5, 2017 at 4:18 comment added Mr.Wizard @AliHashmi I made yet another major revision to my answer. It turns out that (IMHO) Leonid's code was the better starting point, but it needs a little help to be competitive.
Feb 5, 2017 at 3:21 comment added Mr.Wizard @AliHashmi I took a break for dinner but now I am playing with this problem again. Contrary to an earlier statement ReplaceList does produce different output, e.g. interval2[2, {1, 2, 3}] gives {{1, 2}, {2, 3}}, but that is not the output requested in the Question. Perhaps kglr will comment when he is surprised to see this long chain of comments on an old post.
Feb 5, 2017 at 1:35 comment added Ali Hashmi @Mr.Wizard yours is ~ 3 times faster. Tried with a RandomSample of 3000000 primes ! wow
Feb 5, 2017 at 1:27 comment added Mr.Wizard @AliHashmi I think I got it right this time. Since I have your eyes on it would you mind checking for me?
Feb 5, 2017 at 1:10 comment added Ali Hashmi @Mr.Wizard looking forward to the update :)
Feb 5, 2017 at 0:53 comment added Mr.Wizard @AliHashmi actually on a separate point I just realized that my update is bogus because I still assumed a sorted list. Now I have to see if I can fix that without looking too silly. ;-p
Feb 5, 2017 at 0:51 comment added Mr.Wizard @AliHashmi I just checked again and I find ReplaceList marginally slower on the test currently at the bottom of my answer.
Feb 5, 2017 at 0:49 comment added Mr.Wizard @AliHashmi and kglr, please see my updated answer.
Feb 5, 2017 at 0:24 comment added Ali Hashmi @Mr.Wizard actually i am amazed. With the second method interval2 I literally see no difference in performance whether I use ReplaceList or Replace.
Feb 5, 2017 at 0:03 comment added Mr.Wizard @AliHashmi At a glance I cannot see why kglr chose ReplaceList over Replace; the use of the former prevents early exit behavior and given the sort I don't think multiple matches make sense? Also, thank you for commenting as I don't think I ever saw kglr's interval2 which is a very nice method. I wonder if it can be bettered using Ordering.
Feb 5, 2017 at 0:03 comment added Ali Hashmi @kglr my bad, Replace is as bad with conditional checks for very large lists and when the value is located close to the end of the list.
Feb 4, 2017 at 23:55 comment added Ali Hashmi @kglr nevertheless your second method is extremely fast !! + 1
Feb 4, 2017 at 23:49 comment added Ali Hashmi @Mr.Wizard I believe Using Replace rather than ReplaceList will yield much much faster results especially if the list is very long. I tried with the example posted by you for a list of 30000 primes and a value of 1250.4 the speed is 120X slower with ReplaceList with conditional checking on
Jan 21, 2012 at 16:53 history edited kglr CC BY-SA 3.0
added 222 characters in body
Jan 21, 2012 at 13:15 comment added Mr.Wizard I yield; +1 for simplicity.
Jan 21, 2012 at 13:02 comment added kglr Mr.Wizard, i agree. Both your InterpolatingFunction method and Pick-based method in my other answer (after removing Sort from the definition) are uncomparably faster than ReplaceList. However, ReplaceList and pattern-based approaches often have this hard-to-resist simplicity.
Jan 21, 2012 at 12:30 comment added Mr.Wizard This is clever, but it is going to be quite inefficient. This is 10,000X slower than InterpolatingFunction on the data in my answer. This may or may not matter, but it should be noted.
Jan 21, 2012 at 12:22 history answered kglr CC BY-SA 3.0