haskellで魔方陣
全くもってダサイかつ遅い
permutationが遅いのもあるんだろう。
import List main=print $ filter eql $ permutation [1..9] permutation (a:[]) = [[a]] permutation a = concat $ zipWith (\x y->map (x:) (permutation (delete x y))) a $ repeat a eql x = s==(x!!3)+(x!!4)+(x!!5)&&s==(x!!6)+(x!!7)+(x!!8) &&s==(x!!0)+(x!!3)+(x!!6) &&s==(x!!1)+(x!!4)+(x!!7) &&s==(x!!2)+(x!!5)+(x!!8) &&s==(x!!0)+(x!!4)+(x!!8) &&s==(x!!2)+(x!!4)+(x!!6) where s= (x!!0)+(x!!1)+(x!!2)
追記 2008/12/09 12:22:38:
ダサいのは、自分のコードです(笑