SQL Server Performance

Amazing Palindrome

Discussion in 'The Lighter Side of Being a DBA' started by ranjitjain, Dec 8, 2005.

  1. ranjitjain New Member

    Dan Hoey, who had recently graduated, wrote a C program to look for and construct the following beauty:<br /><br />A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa, a gas, an oil, a bird, a yell, a vat, a caw, a pax, a wag, a tax, a nay, a ram, a cap, a yam, a gay, a tsar, a wall, a car, a luger, a ward, a bin, a woman, a vassal, a wolf, a tuna, a nit, a pall, a fret, a watt, a bay, a daub, a tan, a cab, a datum, a gall, a hat, a fag, a zap, a say, a jaw, a lay, a wet, a gallop, a tug, a trot, a trap, a tram, a torr, a caper, a top, a tonk, a toll, a ball, a fair, a sax, a minim, a tenor, a bass, a passer, a capital, a rut, an amen, a ted, a cabal, a tang, a sun, an ass, a maw, a sag, a jam, a dam, a sub, a salt, an axon, a sail, an ad, a wadi, a radian, a room, a rood, a rip, a tad, a pariah, a revel, a reel, a reed, a pool, a plug, a pin, a peek, a parabola, a dog, a pat, a cud, a nu, a fan, a pal, a rum, a nod, an eta, a lag, an eel, a batik, a mug, a mot, a nap, a maxim, a mood, a leek, a grub, a gob, a gel, a drab, a citadel, a total, a cedar, a tap, a gag, a rat, a manor, a bar, a gal, a cola, a pap, a yaw, a tab, a raj, a gab, a nag, a <font color="red">p</font id="red">agan, a bag, a jar, a bat, a way, a papa, a local, a gar, a baron, a mat, a rag, a gap, a tar, a decal, a tot, a led, a tic, a bard, a leg, a bog, a burg, a keel, a doom, a mix, a map, an atom, a gum, a kit, a baleen, a gala, a ten, a don, a mural, a pan, a faun, a ducat, a pagoda, a lob, a rap, a keep, a nip, a gulp, a loop, a deer, a leer, a lever, a hair, a pad, a tapir, a door, a moor, an aid, a raid, a wad, an alias, an ox, an atlas, a bus, a madam, a jag, a saw, a mass, an anus, a gnat, a lab, a cadet, an em, a natural, a tip, a caress, a pass, a baronet, a minimax, a sari, a fall, a ballot, a knot, a pot, a rep, a carrot, a mart, a part, a tort, a gut, a poll, a gateway, a law, a jay, a sap, a zag, a fat, a hall, a gamut, a dab, a can, a tabu, a day, a batt, a waterfall, a patina, a nut, a flow, a lass, a van, a mow, a nib, a draw, a regular, a call, a war, a stay, a gam, a yap, a cam, a ray, an ax, a tag, a wax, a paw, a cat, a valley, a drib, a lion, a saga, a plat, a catnip, a pooh, a rail, a calamus, a dairyman, a bater, a canal-Panama. <br /><br />This is the world's longest PALINDROME. (The letter in red is the center of the palindrome)[<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br />
  2. Madhivanan Moderator

    Nice [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br /><br />Without spaces it may be MALAYALAM (one of the South Indian Languages)<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
  3. FrankKalis Moderator


    DECLARE @input VARCHAR(8000)
    SET @input = 'add here this long string from above'

    SET @input = UPPER(REPLACE(REPLACE(REPLACE(REPLACE(@input,' ',''),',',''),'''',''), '-',''))

    SELECT
    CASE
    WHEN SUBSTRING(@input,1,LEN(@input)/2) = REVERSE(SUBSTRING(@input,(LEN(@input)+3)/2,LEN(@input)/2))
    THEN 1
    ELSE 0
    END AS IsPalindrome

    IsPalindrome
    ------------
    1

    (1 row(s) affected)


    --
    Frank Kalis
    Microsoft SQL Server MVP
    http://www.insidesql.de
    Heute schon gebloggt?http://www.insidesql.de/blogs
    Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)
  4. Madhivanan Moderator

    Very Nice Frank. But MALAYALAM is correct [8D]

    Madhivanan

    Failing to plan is Planning to fail
  5. Madhivanan Moderator

    But Isnt it enough?

    DECLARE @input VARCHAR(8000)
    SET @input = 'whatever_you_want_to_test'
    Select Case when @input=Reverse(@input) then 1 else 0 end as Palindrome


    Madhivanan

    Failing to plan is Planning to fail
  6. FrankKalis Moderator

    Doh, looks like my logic was wayy to complicated. [<img src='/community/emoticons/emotion-3.gif' alt=':O' />]<br /><br />--<br />Frank Kalis<br />Microsoft SQL Server MVP<br /<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a><br />Heute schon gebloggt?<a target="_blank" href=http://www.insidesql.de/blogs>http://www.insidesql.de/blogs</a><br />Ich unterstütze PASS Deutschland e.V. <a target="_blank" href=http://www.sqlpass.de>http://www.sqlpass.de</a>) <br />
  7. Madhivanan Moderator

    &gt;&gt;Doh, looks like my logic was wayy to complicated.<br /><br />I think something is in your code that keeps query from being errored by input [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
  8. Luis Martin Moderator

    Nice one.

    Luis Martin
    Moderator
    SQL-Server-Performance.com

    One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important
    Bertrand Russell


    All postings are provided “AS IS” with no warranties for accuracy.



Share This Page