r/dailyprogrammer • u/Cosmologicon 2 3 • Dec 04 '12
[12/4/2012] Challenge #114 [Difficult] Longest word ladder
What's the longest valid word ladder you can make using this list of 3,807 four-letter words without repeating any words? (Normally a word ladder would require you to take the shortest possible path between two words, but obviously you don't do that here.)
Here's a ladder I found of 1,709 words. What's the best you can do? Also post the code you used to generate it, of course.
Thanks to Thomas1122 for suggesting this challenge on /r/dailyprogrammer_ideas!
35
Upvotes
9
u/adzeitor 0 0 Dec 04 '12 edited Dec 09 '12
3211 http://pastebin.com/X8gViRNP
3538 http://pastebin.com/A2JFp98c
3542 after 1 hour :D
EDIT1: add max depth and sort list by ham frequency... This gets 3538
EDIT2: leonardo_m changes.
haskell (input in words.txt, current result in res.txt):
7
u/Ledrug 0 2 Dec 04 '12 edited Dec 04 '12
Perl, does greedy exhaustive depth-first search. Found 2394 length after a few seconds, which is certainly not the longest possible.
A file named "longest" is written every time a new record is found.
EDIT: reversed order of candidates, now it gets to 3239 pretty quickly (and gets stuck there instead)
EDIT2: 3429 http://pastebin.com/5uZYxCfg
6
u/Ledrug 0 2 Dec 11 '12
C. Finds 3545 in about a second. Longest chain is saved in file "longest" under the current directory.
3
u/thehivemind5 Dec 24 '12
I know I'm late to the party, but here's my java solution Longest Ladder found: 3606 https://gist.github.com/4366900
2
u/leonardo_m Dec 10 '12
D solution, finds a chain of 3188 words in less than a second. This code is over-engineered and probably contains too many optimizations. A program half as long is only a little slower and finds the same chain length. So this code is a partial failure.
2
u/OldPeoples 0 0 Dec 13 '12 edited Dec 13 '12
C++ So I made a working program for this, but at the rate it was running at, it would have taken a month to finish executing. Could anybody help me with optimization? I attempted an implementation of a depth-first search. There are fragments in the program from when I was trying to use a linked list. In reality, I just needed a vector of nodes. You can click here for the pastebin, or see the code below. Thanks in advance!
EDIT: From what I can tell, the answer is a tiny bit more than 3300;
2
u/usea Dec 04 '12 edited Dec 04 '12
C# exhaustive, depth-first search.
still running, with 3200 as the current longest
code
1
u/OldPeoples 0 0 Dec 10 '12
I'm attempting this right now using C++. I'm assuming I should use a linked list and a depth-first search?
1
u/robin-gvx 0 2 Dec 04 '12 edited Dec 04 '12
Python, it's still running, but has given a temporary longest word ladder of 2772 words: (between look and leap, haven't tried anything else yet) (EDIT: still running, still no longer ladder)