search-algorithms
search-algorithms copied to clipboard
Elixir algorithms don't work on Elixir 1.5.2
BFS fails on line 31:
Bug Bug ..!!** (ArgumentError) the Access calls for keywords expect the key to be an atom, got: 1 (elixir) lib/access.ex:329: Access.get/3 lib/bsf.ex:39: anonymous fn/3 in Bfs.frontier_adj/2 (elixir) lib/enum.ex:1826: Enum."-reduce/3-lists^foldl/2-0-"/3 lib/bsf.ex:31: Bfs.visit_frontier/3
And DFS Fails on line 22:
Bug Bug ..!!** (ArgumentError) the Access calls for keywords expect the key to be an atom, got: 1 (elixir) lib/access.ex:329: Access.get/3 lib/dfs.ex:22: Dfs.visit/3
if the data structure is changed to a Map then the code should work.
Dfs.visit(1, %{
1 => [2, 3, 4],
2 => [1, 5, 6],
3 => [1],
4 => [1, 7, 8],
5 => [2, 9, 10],
6 => [2],
7 => [4, 11, 12],
8 => [4],
9 => [5],
10 => [5],
11 => [7],
12 => [7]
})
[1, 2, 5, 9, 10, 6, 3, 4, 7, 11, 12, 8]