Skip to content

Instantly share code, notes, and snippets.

@0rca
Created September 30, 2015 15:05
Show Gist options
  • Save 0rca/2d7764e40746ecf783da to your computer and use it in GitHub Desktop.
Save 0rca/2d7764e40746ecf783da to your computer and use it in GitHub Desktop.
module NewModule2 where
import Data.List.Split
--Написать функцию parts, которая для данного списка проверяет, можно ли его разбить
--на несколько строго возрастающих кусков одинаковой длины.
--
--Длина кусков должна быть не меньше 2. Кусок может быть и только один.
aList = [1,2,3,4, 1,2,3,4,5,6,7,8,9,11, 1,2,3,4,5,6,8,11, 5,6]
diff :: Num a => [a] -> [a]
diff xs = zipWith (-) (tail xs) xs
extendR xs = xs ++ [last xs]
diff' = extendR . map signum . diff
lengths :: (Ord a,Num a) => [a] -> [Int]
lengths = map length . split (dropFinalBlank . keepDelimsR . whenElt $ (<=0)) . diff'
parts = (>1) . foldl1 gcd . lengths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment