day6: update - parser combinators have clouded my judgement
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
		
							
								
								
									
										6
									
								
								day6.hs
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								day6.hs
									
									
									
									
									
								
							@@ -1,5 +1,4 @@
 | 
				
			|||||||
import Data.List (nub)
 | 
					import Data.List (nub)
 | 
				
			||||||
import Text.ParserCombinators.ReadP
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
main :: IO ()
 | 
					main :: IO ()
 | 
				
			||||||
main = do
 | 
					main = do
 | 
				
			||||||
@@ -9,7 +8,6 @@ main = do
 | 
				
			|||||||
  putStr "Q2: "
 | 
					  putStr "Q2: "
 | 
				
			||||||
  print $ q2 input
 | 
					  print $ q2 input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
q1, q2 :: String -> Int
 | 
					q1, q2 :: String -> Int
 | 
				
			||||||
q1 = length . parse 4
 | 
					q1 = length . parse 4
 | 
				
			||||||
q2 = length . parse 14
 | 
					q2 = length . parse 14
 | 
				
			||||||
@@ -20,6 +18,4 @@ parse n a = parse' n (splitAt n a)
 | 
				
			|||||||
parse' :: Int -> (String, String) -> String
 | 
					parse' :: Int -> (String, String) -> String
 | 
				
			||||||
parse' n (a, b)
 | 
					parse' n (a, b)
 | 
				
			||||||
  | length (nub (drop (length a - n) a)) == n = a
 | 
					  | length (nub (drop (length a - n) a)) == n = a
 | 
				
			||||||
  | otherwise =
 | 
					  | otherwise = parse' n (a ++ [head b], tail b)
 | 
				
			||||||
    let (c, cs) = last $ readP_to_S get b
 | 
					 | 
				
			||||||
     in parse' n (a ++ [c], cs)
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user