Last active
August 29, 2015 14:25
-
-
Save qzchenwl/57ec6f993bba6566dacd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.List | |
vertices = "ABCDEFGHIJK" | |
edges = ["ADB", "AEC", "AFHJ", "AGIK", "BJKC", "BHIE", "DFGE"] | |
combinations n = filter ((==n) . length) . subsequences | |
inSameEdge xs = or [ all (`elem` edge) xs | edge <- edges] | |
isTriangle (a:b:c:[]) = all inSameEdge [[a, b], [a, c], [b, c]] && not (inSameEdge [a, b, c]) | |
triangles = filter isTriangle (combinations 3 vertices) | |
main = print triangles |
Author
qzchenwl
commented
Jul 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment