[Openmcl-devel] bit string matching

Lonnie Cumberland lonnie at biofuelstechnologyinc.com
Wed Jan 5 13:38:48 UTC 2011


Greetings All,

Firstly, let me state that this is not any type of homework problem as
was suggested by Lou earlier. I was namely in the process of seeing if
a type of "max-palindrome" function already existed so that it would
same me some time in having to re-code that part.

On the other side, I am running Clozure 1.6 from
http://ccl.clozure.com/ on a Windows platform as well.

I just came across a couple of implementations, but could not seem to
get them to run on Clozure ccl.


FROM: http://osdir.com/ml/clojure/2010-10/msg00669.html
-------------------------------------------------------------------
(def st
"FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")

(defn longest-palindrome-at [^String st ind1 ind2]

(let [ind1 (int ind1)
ind2 (int ind2)]
(if (= (.charAt st ind1)
(.charAt st ind2))
(if (or (zero? ind1) (= ind2 (dec (.length st))))
[ind1 ind2]
(recur st (dec ind1) (inc ind2)))
[(inc ind1) (dec ind2)])))

(defn longest [^String st]
(let [[ind1 ind2]
(apply max-key (fn [[i1 i2]] (let [i1 (int i1) i2 (int i2)]
(- i2 i1)))
(concat
(for [i (range (.length st))]
(longest-palindrome-at st i i))
(for [i (range 1 (.length st))]
(longest-palindrome-at st (dec i) i))))]
(.substring st ind1 (inc ind2))))
------------------------------------------------------------------

Any ideas on this?

Thanks in advance,
Lonnie

On Tue, Jan 4, 2011 at 5:23 PM, Lou Vanek <lou.vanek at gmail.com> wrote:
> Sorry, that's n^3 in time, not n^2. Space calc still holds.
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>



More information about the Openmcl-devel mailing list