Skip to content

Instantly share code, notes, and snippets.

@314maro
Created March 2, 2014 13:05
Show Gist options
  • Select an option

  • Save 314maro/9306309 to your computer and use it in GitHub Desktop.

Select an option

Save 314maro/9306309 to your computer and use it in GitHub Desktop.
†を()に
import Data.List
parens 0 = [""]
parens n = [ x ++ y
| a <- [0..n-2]
, let b = n-2-a
, x <- map ('(':) (parens a)
, y <- map (')':) (parens b)
]
merge c s1 s2 = snd $ mapAccumL f s1 s2
where
f (x:xs) c' | c == c' = (xs,x)
f xs c' = (xs,c')
solve c xs = [ merge c ys xs | ys <- parens $ length $ elemIndices c xs ]
f = solve '†'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment