Skip to content

Instantly share code, notes, and snippets.

@BelegCuthalion
Last active May 10, 2019 16:57
Show Gist options
  • Save BelegCuthalion/f80c19880bae1b2255657443f635ce35 to your computer and use it in GitHub Desktop.
Save BelegCuthalion/f80c19880bae1b2255657443f635ce35 to your computer and use it in GitHub Desktop.
Rostam is preparing to confront rather _complex_ demon, with many eyes and heads. If he cut any of her n-eyed heads, she grows n-1 new heads: a k-eyed head for each k in {1,...,n-1}. The cunning warrior he is, Rostam ponders upon this task; How many heads he should sever? Does its order make any difference? Is it even possible in his mortal fini…
{-# LANGUAGE UnicodeSyntax #-}
type Writer a = (a, String)
type CutMethod = [Integer] → [Integer] → [Integer]
type CutDiary = (CutMethod, Writer [Integer])
return ∷ a → Writer a
return x = (x, "")
depthFirst ∷ CutMethod
depthFirst = (++)
breadthFirst ∷ CutMethod
breadthFirst = \newHeads → \oldOnes → oldOnes ++ newHeads
merge :: [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge (x:xs) (y:ys) = x : y : merge xs ys
mergeMethod ∷ CutMethod
mergeMethod = \newHeads → \oldOnes → merge newHeads oldOnes
cut ∷ CutDiary → CutDiary
cut (c, ([], s)) = (c, ([], s))
cut (cutMethod, (h : t, s)) = cut (cutMethod, (cutMethod [1..h-1] t, s ++ (show (h : t))))
printDiary ∷ CutDiary → String
printDiary (_, (_, s)) = s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment