The beauty of Haskell

Ah, the beauty of Haskell, solving the graceful labeling node generation (brute force mind you, but still...)

vonKoch edges = do
    let n = length edges + 1
    nodes <- permutations [1..n]
    let nodeArray = listArray (1,n) nodes
    let dists = sort $ map (\(x,y) -> abs (nodeArray ! x - nodeArray ! y)) edges
    guard $ and $ zipWith (/=) dists (tail dists)
    return nodes


(solution found here: http://www.haskell.org/haskellwiki/99_questions/Solutions/92)

Comments

Popular posts from this blog

Javascript factorial - performance considerations

Manual pages optimized for search as well as for reading

To escape or not to escape. Part 2.