day6
This commit is contained in:
		
							
								
								
									
										21
									
								
								day6/main.hs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								day6/main.hs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					import System.IO
 | 
				
			||||||
 | 
					import Data.List
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					marker :: Int -> Int -> String -> Int
 | 
				
			||||||
 | 
					marker p n s@(_:xs)
 | 
				
			||||||
 | 
					    | unique == n = p+n
 | 
				
			||||||
 | 
					    | otherwise   = marker (p+1) n xs
 | 
				
			||||||
 | 
					    where
 | 
				
			||||||
 | 
					        unique = length $ nub $ take n s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handler :: String -> String
 | 
				
			||||||
 | 
					handler s = (show $ marker 0 4 s) ++ "\n" ++
 | 
				
			||||||
 | 
					            (show $ marker 0 14 s) ++ "\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					main :: IO ()
 | 
				
			||||||
 | 
					main = do
 | 
				
			||||||
 | 
					    interact handler
 | 
				
			||||||
		Reference in New Issue
	
	Block a user