Skip to content

Instantly share code, notes, and snippets.

@kashmervil
Last active August 29, 2015 14:09
Show Gist options
  • Save kashmervil/665ce4e3ac9e04b6204e to your computer and use it in GitHub Desktop.
Save kashmervil/665ce4e3ac9e04b6204e to your computer and use it in GitHub Desktop.
Strange behavior of the course testing system
import Data.Set
countDifferentVars rules variables =
size $ Prelude.foldl (\acc (l,r) ->
let sets = Data.Set.fold (\s sacc -> if (l `member` s) || (r `member` s)
then s:sacc else sacc) [] acc in
case sets of [x,y] -> (x `union` y) `insert` (x `delete` (y `delete` acc))
_ -> acc) (fromList (Prelude.map singleton variables)) rules
import Data.Set
countDifferentVars rules variables =
size $ Prelude.foldl (\acc (l,r) ->
let sets = Data.Set.fold (\s sacc -> if (l `member` s) || (r `member` s)
then s:sacc else sacc) [] acc in
case (sets,(l == r)) of ([x,y],_) -> (x `union` y) `insert` (x `delete` (y `delete` acc))
(_,True) -> acc
_ -> empty) (fromList (Prelude.map singleton variables)) rules
import Data.Set
countDifferentVars rules variables =
fst $ Prelude.foldl (\(c,acc) (l,r) ->
let sets = Data.Set.fold (\s (l_set, r_set) ->
let e = ((l `member` s),(r `member` s)) in
case e of (True, False) -> (Just s, r_set)
(False, True) -> (l_set, Just s)
_ -> (l_set, r_set)) (Nothing,Nothing) acc in
case sets of (Just x, Just y) -> (c - 1,(x `union` y) `insert` (x `delete` (y `delete` acc)))
(Just x, Nothing) -> (c,(r `insert` x) `insert` (x `delete` acc))
(Nothing, Just y) -> (c,(l `insert` y) `insert` (y `delete` acc))
_ -> (c,(l `insert` (singleton r)) `insert` acc))
(let set = fromList (Prelude.map singleton variables) in (size set, set)) rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment