Skip to content

Instantly share code, notes, and snippets.

@kei-q
Last active December 2, 2017 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kei-q/8199ca86aa5dad891b0cf63db24515e3 to your computer and use it in GitHub Desktop.
Save kei-q/8199ca86aa5dad891b0cf63db24515e3 to your computer and use it in GitHub Desktop.
module Lib where
import Data.List.Split
import Data.List
solve :: String -> String
solve = intercalate "|" . map (intercalate "," . map show) . solve' . splitOn ","
solve' :: [String] -> [[Int]]
solve' [p1,p2] = [a ++ b | a <- nub $ calc 0 ns p1 , let b = ns \\ a , calc 0 b p2 /= [] ]
where
len = length p1
ns = sort ([1..len]++[1..len])
solve' _ = error "solve'"
calc :: Int -> [Int] -> String -> [[Int]]
calc _ _ [] = [[]]
calc _ [] _ = []
calc n xs (c:cs) = [y:ys | y:xs' <- tails xs , if c == 'x' then even y else odd y , n <= y , ys <- calc y xs' cs ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment