JoelSjogren icon

minimal.hs

JoelSjogren | PRO | 02/11/21 07:56:55 PM UTC | 0 ⭐ | 14040 👁️ | Never ⏰ | []
Haskell |

690 B

|

None

|

0 👍

/

0 👎

{-# LANGUAGE FlexibleInstances #-}
import Data.Set (Set,elems,cartesianProduct,fromList,empty,insert,singleton,
                union,unions)
 
data CombinatorialProblem a = CP
  {
    bound :: Set a,
    close :: Set a -> Set a
  }
 
enumerate :: CombinatorialProblem a -> Set a
enumerate cp = iterate' f null (empty, singleton (close cp empty))
  where
    f (old, new) = (union old new, fromList fresh)
      where
        fresh = [close cp (insert a s) | a <- elems (bound cp), s <- elems new]
 
iterate' :: ((a,a) -> (a,a)) -> (a -> Bool) -> (a,a) -> a
iterate' f p x = let (x0,x1) = iterate'' x in x0
  where
    iterate'' x = if p (let (x0,x1) = x in x1) then x else iterate'' (f x)
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎