Re: Help to optimize palindrome search from input file

2010-10-22 Thread siddarth shankar
very nice! faster and more succinct :) also means we can read in smaller chunks from large strings as required.. On Oct 21, 4:15 am, Kent wrote: > I took a different approach, not wildly "clojurish", type-hinted, > ugly, but also pretty fast.  About 1.2ms on my machine (after about 10 > runs so t

Re: Help to optimize palindrome search from input file

2010-10-20 Thread Kent
I took a different approach, not wildly "clojurish", type-hinted, ugly, but also pretty fast. About 1.2ms on my machine (after about 10 runs so the JIT has done its magic). The approach is to look at each character, or pair of adjacent characters, as the potential center of a palindrome and then

Re: Help to optimize palindrome search from input file

2010-10-19 Thread siddarth shankar
someone posted a 200,000 char test-string: http://pastebin.com/raw.php?i=a8veAND3 (doesn't view properly in chrome, view-source and save) and the previous code failed pretty hard.. so, new approach - one pass has all the information on where each character occurs. so, create a map with each char

Re: Help to optimize palindrome search from input file

2010-10-15 Thread siddarth shankar
i could get it down to around 1.6/1.7 seconds s...@sid-:~$ time clojure dummy.clj woohoo palindrome: eve woohoo palindrome: ranynar real0m1.739s user0m2.088s sys 0m0.124s made a couple of changes - only call 'palindrome?' for substrings between identical characters(between

Re: Help to optimize palindrome search from input file

2010-10-13 Thread Btsai
I think the indexing in all-combs may be off, causing it to miss certain combinations/substrings. user=> (all-combs "abc") ("a" "ab") I used this instead: (defn substrings [s] (let [length (count s)] (for [i (range length) j (range (inc i) (inc length))] (subs s i j us

Re: Help to optimize palindrome search from input file

2010-10-13 Thread Stephen C. Gilardi
On Oct 12, 2010, at 3:02 PM, tonyl wrote: > (defn palindrome? [s] > (= s (reduce str (reverse s One opportunity to micro-optimize is to replace "reduce str" with "apply str". str uses a StringBuilder object to build a string from its arguments. When you use reduce, the code walks down s a

Re: Help to optimize palindrome search from input file

2010-10-12 Thread pkw
I'm just replying because I also do this in clojure and my level is also really slow: http://github.com/krsanky/greplin-challenge/blob/master/greplin-challenge/src/greplin_challenge/level1.clj :) --paul wisehart -- You received this message because you are subscribed to the Google Groups "Cloj

Re: Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
I new the palindrome? function wasn't good in performance, but I didn't think it would be that bad. The type hinting does improve performance plus a mid way to compare. Thanks for pointing that out and the max-key function. On Oct 12, 4:15 pm, Justin Kramer wrote: > The 'palindrome?' function can

Re: Help to optimize palindrome search from input file

2010-10-12 Thread Justin Kramer
The 'palindrome?' function can be made much faster. Your version -- which is idiomatic and fine when perf isn't a factor -- turns the test string into a sequence, reverses it, turns it back into a string, then checks for full equality with the original. There are faster (if uglier) ways to check fo

Re: Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
So for returns a lazy-seq of the combinations and I am forcing it to process the values by filtering. mmm... I still tried your approach and nothing changed in processing time. I changed the for form to filter as it is pairing the combinations, I didn't think it would make any difference since I ju

Re: Help to optimize palindrome search from input file

2010-10-12 Thread Sean Grove
I actually played with this on Saturday morning while waiting for a friend, and thought it was an interesting problem. Your example is spending most of its time filtering with palindrome? across all 682695 items generated by all-combs. To see, try: (defn tony [] (def source "I like racecars t

Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
Hi, I just started to learn clojure in a more serious way and I am doing the first level of the greplin challenge. I made it to work with a short palindrome like the example they give me, but when it comes to work with the input file, it takes for ever and I have to stop it. $ time clj level1.clj