I've been trying to solve an archived ITA Software puzzle known as Sling Blade Runner for a few days now. The gist of the puzzle is as follows:
"How long a chain of overlapping movie titles, like Sling Blade Runner, can you find?"
Use the following listing of movie titles: MOVIES.TXT. Multi-word overlaps, as in "License to Kill a Mockingbird," are allowed. The same title may not be used more than once in a solution. Heuristic solutions that may not always produce the greatest number of titles will be accepted: seek a reasonable tradeoff of efficiency and optimality.
The file MOVIES.TXT contains 6561 movie titles in alphabetical order.
My attempt at a solution has several parts.
Graph Construction:
What I did was map every movie title to every other movie title it could chain to (on it's right). What I end up with as my graph is a Map[String, List[String]]
. You can see the graph that was built using this process here.
Graph Traversal:
I did a Depth First Search using every node (every key in the map) as a starting node of the search. I kept track of the depth at which each node was visited during the search, and this was tagged in the nodes returned by the DFS. What I ended up with was a List[List[Node]]
where every List[Node]
in the List was the DFS tree from a particular search.
Finding the longest chain:
I took the results of all the graph traversals in the previous step, and for every List[Node]
I sorted the list by the depth values I tagged the nodes with previously, in descending order. Then starting with the head of the list (which gives me the deepest node visited in the DFS) I backtrack through the nodes to build a chain. This gave me a List[List[String]]
where every List[String]
in the List was the longest chain for that particular DFS. Sorting the List[List[String]]
by the size of each List[String]
and grabbing the head then gave me the largest chain.
Results:
The longest chain found with my algorithm was 217 titles long. The output can be viewed here.
I've only been able to find a few other attempts by Googling, and it seems every other attempt has produced longer chains than what I was able to accomplish. For example this post states that Eric Burke found a chain 245 titles long, and a user by the name of icefox on Reddit found a chain that was 312 titles long.
I can't think of where my algorithm is failing to find the longest chain, given other people have found longer chains. Any help/guidance is much appreciated. If you'd like to review my code, it can be found here (it's written in Scala and I just started learning Scala so forgive me if I made some noob mistakes).
Update:
I made some changes to my algorithm, which now finds chains of length 240+. See here