Click here to Skip to main content
15,888,330 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Get the date from SQL Server Pin
PIEBALDconsult16-Sep-09 5:39
mvePIEBALDconsult16-Sep-09 5:39 
GeneralRe: Get the date from SQL Server Pin
supercat917-Sep-09 5:40
supercat917-Sep-09 5:40 
GeneralRe: Get the date from SQL Server Pin
irol17-Sep-09 6:10
professionalirol17-Sep-09 6:10 
GeneralRe: Get the date from SQL Server Pin
MaksimP25-Sep-09 9:48
MaksimP25-Sep-09 9:48 
GeneralRe: Get the date from SQL Server Pin
MaksimP25-Sep-09 9:45
MaksimP25-Sep-09 9:45 
GeneralRe: Get the date from SQL Server Pin
Gordon Kushner12-Oct-09 5:17
Gordon Kushner12-Oct-09 5:17 
GeneralRe: Get the date from SQL Server Pin
Jane Williams13-Oct-09 3:53
Jane Williams13-Oct-09 3:53 
GeneralAnagram finder PinPopular
justastupidgurl9-Sep-09 3:08
justastupidgurl9-Sep-09 3:08 
Was just asked to convert some VB6 code to C#.

The purpose of the code is to find anagrams. There is a database with a list of words. The input is a string of letters and the code is supposed to spit out any matching anagrams found in the word list.

The idea is to have a 'crossword puzzle' helper tool that can be downloaded from an ad-financed puzzle enthusiasts website, but the client felt it was too slow to use and wondered if C# might be faster.

This is what I found: All possible orders of letters in the input string are derived in a loop, then each one is searched against the database to see if it exists. As you might imagine, with anything except a very short input this yields gazzilions of combinations and takes forever (almost literally) to run.

The first thing I did was a run-once bit of code to sort the letters in each word in the database into alphabetical order, and stick that in as a key field.

To find an anagram, the letters in the input are also sorted into alphabetical order. We then match that to the indexed key field and pull out matching words in the blink of an eye.

The end result runs in milliseconds instead of centuries. Or as the client put it "That C#'s a bit faster than VB6, isn't it?"

Should I now point out that a downloadable C# app is not a good idea? Their user base (presumably little old ladies) would need the net framework on their Win98 PCs, and having downloaded once, they don't need to go back to click on the knitting pattern banner ads. It should run in a browser.

But what do I know? I'm just a stupid girl.

JustAStupidGurl

GeneralRe: Anagram finder Pin
Jeroen De Dauw9-Sep-09 3:48
Jeroen De Dauw9-Sep-09 3:48 
GeneralRe: Anagram finder Pin
justastupidgurl9-Sep-09 4:05
justastupidgurl9-Sep-09 4:05 
GeneralRe: Anagram finder Pin
Jeroen De Dauw9-Sep-09 20:40
Jeroen De Dauw9-Sep-09 20:40 
GeneralRe: Anagram finder Pin
justastupidgurl11-Sep-09 2:58
justastupidgurl11-Sep-09 2:58 
GeneralRe: Anagram finder Pin
akidan11-Sep-09 7:27
akidan11-Sep-09 7:27 
GeneralRe: Anagram finder Pin
Ian Shlasko11-Sep-09 8:05
Ian Shlasko11-Sep-09 8:05 
GeneralRe: Anagram finder Pin
justastupidgurl12-Sep-09 2:37
justastupidgurl12-Sep-09 2:37 
GeneralRe: Anagram finder Pin
ClementsDan11-Sep-09 17:48
ClementsDan11-Sep-09 17:48 
GeneralRe: Anagram finder Pin
justastupidgurl12-Sep-09 2:19
justastupidgurl12-Sep-09 2:19 
GeneralRe: Anagram finder Pin
dawmail33316-Sep-09 2:11
dawmail33316-Sep-09 2:11 
GeneralRe: Anagram finder Pin
dojohansen15-Oct-09 1:25
dojohansen15-Oct-09 1:25 
GeneralHow to group by hour properly. [modified] Pin
Brady Kelly20-Aug-09 22:33
Brady Kelly20-Aug-09 22:33 
GeneralRe: How to group by hour properly. Pin
David Skelly21-Aug-09 0:49
David Skelly21-Aug-09 0:49 
GeneralRe: How to group by hour properly. Pin
Brady Kelly21-Aug-09 0:53
Brady Kelly21-Aug-09 0:53 
GeneralRe: How to group by hour properly. Pin
ClementsDan21-Aug-09 15:22
ClementsDan21-Aug-09 15:22 
GeneralRe: How to group by hour properly. Pin
MaksimP25-Sep-09 10:07
MaksimP25-Sep-09 10:07 
GeneralHow to handle dates _properly_. [modified] Pin
Brady Kelly20-Aug-09 12:31
Brady Kelly20-Aug-09 12:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.