Skip to content

Instantly share code, notes, and snippets.

@Sophia-Gold
Last active April 13, 2018 01:30
Show Gist options
  • Select an option

  • Save Sophia-Gold/ffaeebe1cc6b5f2121dfd0207a52858a to your computer and use it in GitHub Desktop.

Select an option

Save Sophia-Gold/ffaeebe1cc6b5f2121dfd0207a52858a to your computer and use it in GitHub Desktop.
type level `fix` for calculating supernecklace cardinality
{-# LANGUAGE DeriveFoldable #-}
import Data.List
data NList a = [a] :-: (NList [a])
| Nil deriving (Show, Foldable)
fixT :: NList a -> NList a
fixT Nil = Nil
fixT (x :-: Nil) = x :-: (subsequences x :-: Nil)
fixT (x :-: xs) = x :-: f xs
supernecklaceT degree size = length . last . take (degree - 1) $ iterate fixT (enumFromTo 1 size :-: Nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment