I'm looking at the solution to the "Programming Praxis" puzzle "Square-sum puzzle" (https://programmingpraxis.com/2018/01/16/square-sum-puzzle/). The puzzle itself is "Arrange the numbers 1..15 so that all adjacent pairs add up to a perfect square". The given solution (https://programmingpraxis.com/2018/01/16/square-sum-puzzle/2/) is expressed as a graph problem. STep 1 is to create a graph of the numbers 1..15 with adjacent nodes adding up to a perfect square:g = nx.Graph()for i in range(1,16):for tot in (1,4,9,16,25):j = tot-iif 0 < j < 16 and j != i:g.add_edge(i, j)The solution then notes that a depth-first search of the graph will find the solution - the actual code (written in Scheme, so I find it hard to follow) seems to enumerate all depth first paths through the graphs, looking for one that contains all the nodes of the graph. But that's not how a DFS works in NetworkX (and indeed, none of the DFS algorithms in NetworkX seem to address this problem, except in the very basic sense that I can use dfs_successors to manually implement the algorithm in the solution).
Hi,
Could you use the single_source_shortest_path methods
and then check if they are simple paths?
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.