Created
April 28, 2011 05:09
-
-
Save oskimura/945836 to your computer and use it in GitHub Desktop.
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
| {-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-} | |
| {-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-} | |
| {-# LANGUAGE BangPatterns, OverloadedStrings, ScopedTypeVariables #-} | |
| {-# LANGUAGE NoMonomorphismRestriction #-} | |
| module Main where | |
| import Control.Applicative | |
| import Data.List | |
| import Text.Printf | |
| splitBy :: (a -> Bool) -> [a] -> [[a]] | |
| splitBy p [] = [] | |
| splitBy p xs = a : (splitBy p $ dropWhile p $ b) | |
| where | |
| (a, b) = break p xs | |
| split :: String -> [String] | |
| split = splitBy (==' ') | |
| -- input = lines <$> readFile "input.txt" | |
| --input = lines <$> getContents | |
| input = getContents | |
| xs = "ROYGBIV" ++ xs | |
| solve :: Int -> String | |
| solve n = concat . take 1 $ [ zs | zs <- permutations $ ys, check zs] | |
| where ys = take n xs | |
| check xs = g ys | |
| where | |
| n = 4 | |
| f xs = (==n) . length . nub . take n $ xs | |
| g [x1,x2,x3,x4] = f [x1,x2,x3,x4] | |
| g xs = (f xs) && g (tail xs) | |
| ys = let as = take n xs in xs ++ as | |
| f xs = (==n) . length . nub . take n $ xs | |
| where n = 4 | |
| g [x1,x2,x3,x4] = [f $ [x1,x2,x3,x4]] | |
| g xs = (f xs) : g (tail xs) | |
| rr :: String -> Int | |
| rr = read | |
| main :: IO () | |
| main = do { ns <- input | |
| ; printf "%s" . solve . rr $ ns | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment