In answering this question on Stack Overflow, I decided to stretch my legs in Haskell a bit to see if I could implement a solution to find the count of lucky triples in a list of ints.
A lucky triple is any triple
(j, k, l) where
j <= k <= l and
l `mod` k == 0 && k `mod` j == 0. A correct implementation counts how many unique combinations of elements of an
[Int] are valid lucky triples.
import Data.List (sort) answer :: [Int] -> Int answer xs = foldr ((+) . foldr ((+) . length) 0) 0 $ twoStepFactors where twoStepFactors = map mapFactors $ mapFactors $ sort xs mapFactors :: [Int] -> [[Int]] mapFactors xs = mapFactors' xs  mapFactors'  acc = acc mapFactors' (x:xs) acc = mapFactors' xs newAcc where factors = filter ((==0) . (`mod` x)) xs newAcc | null factors = acc | otherwise = acc ++ [factors]