これは Haskell でのブルート フォースです (開始までに約 10 秒かかります)。
コード:
import Control.Monad (guard, replicateM)
developers = ["A", "B", "C", "D", "E", "F"]
combinations = filter (\x -> head x /= last x) . replicateM 2 $ developers
makeWeek week =
if length week == length developers
then [week]
else do
review <- combinations
guard (notElem (take 1 review) (map (take 1) week)
&& notElem (drop 1 review) (map (drop 1) week)
&& notElem (reverse review) week
&& notElem review week)
makeWeek (review:week)
solve = solve' [] where
solve' weeks =
if length weeks == length developers - 1
then [weeks]
else do
week' <- makeWeek []
guard (all (\x -> notElem x (concat . take (length developers - 1) $ weeks)) week')
solve' (week':weeks)
サンプル出力:
*Main> solve
[[[["F","B"],["E","A"],["D","C"],["C","E"],["B","D"],["A","F"]]
,[["F","C"],["E","B"],["D","A"],["C","D"],["B","F"],["A","E"]]
,[["F","A"],["E","C"],["D","B"],["C","F"],["B","E"],["A","D"]]
,[["F","E"],["E","D"],["D","F"],["C","B"],["B","A"],["A","C"]]
,[["F","D"],["E","F"],["D","E"],["C","A"],["B","C"],["A","B"]]],...etc