Magic Triangle - Solution
I first saw this Magic Triangle puzzle in CSIRO ’s Double Helix here : You are given a triangle with circle on each point and on each side: Magic Triangle Then, using the numbers from 1 to 6, arrange them in a triangle with three numbers on each side. Swap them around until the sides all add up to the same number. Finally, sum each side to 10. Method Let’s label the triangle: starting from any vertex label the nodes: Labelled Magic Triangle The method to solve this problem is broken into the following steps: get all permutations of numbers 1 to 6 as a, b, c, d, e, f filter permutation to satisfy conditions: a + b + c == c + d + e == e + f + a and final condition: a + b +c == 10 Using Haskell All permutations of numbers 1 to 6: import Data.List permutations [ 1 .. 6 ] This will give 6! = 720 permutations. Filter on sides summing up to the same value: [ [(a,b,c), (c,d,e), (e,f,a)] | [a,b,c,d,e,f] <- permutations [ 1 .. 6 ], a + b + c ==...