Last active
December 2, 2017 05:48
-
-
Save kei-q/8199ca86aa5dad891b0cf63db24515e3 to your computer and use it in GitHub Desktop.
http://mtsmfm.github.io/2017/11/04/doukaku-e19.html のHaskellによる解答例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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