3 ms·
Translating that into Haskell, I get: check_each :: Int -> [Int] -> Bool -> Int -> (Bool,Bool,Int) check_each x (y:_) _ last | y==x && x==last = (True,Fals
by a1369209993 7y ago
Translating that into Haskell, I get:
check_each :: Int -> [Int] -> Bool -> Int -> (Bool,Bool,Int)
check_each x (y:_) _ last | y==x && x==last = (True,False,x)
check_each x (y:_) _ last | y>x && x==last = (True,True,x)
check_each x (y:_) found _ | y>x = (True,found,x)
check_each x _ found _ = (False,found,x)
is_valid :: (Bool,Bool,Int) -> [Int] -> Bool
is_valid (False,_,_) _ = False
is_valid (True,True,-1) [_] = False
is_valid (True,True,_) [_] = True
is_valid (True,found,shortDup) (h:t) = is_valid (check_each h t found shortDup) t
which is ugly, certainly, but compiles fine (ghc). The uglyness mainly comes from the data structures, and I don't know enough about the domain to suggest better ones (there might not be better ones).
- macintux 7y agoWell, it was code I threw together quickly for Advent of Code, so try not to be too hard on it.
- a1369209993 7y agoEh, like I said, that might be the best you can do for a messy problem domain. I'm still not sure what you meant by multiple function heads though.