We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Password Cracker FP
Password Cracker FP
Sort by
recency
|
7 Discussions
|
Please Login in order to post a comment
this was easy, scala:
import Control.Monad import Data.List (isPrefixOf)
main :: IO () main = readLn >>= flip replicateM_ testCase
testCase :: IO () testCase = do _ <- getLine passwords <- fmap words getLine guess <- getLine case sequence (loginAttempt passwords guess) of Nothing -> putStrLn "WRONG PASSWORD" Just xs -> putStrLn $ unwords xs
loginAttempt :: [String] -> String -> [Maybe String] loginAttempt _ [] = [] loginAttempt passwords guess = case matching of [] -> [Nothing] (x:_) -> Just x : loginAttempt passwords (drop (length x) guess) where matching = filter (flip isPrefixOf guess) passwords
The name "Password Cracker FP" made me wonder if the suffix "FP" meant that there was a non-FP version of this problem.
And indeed there is:
Algorithms > Recursion > Password Cracker
So I entered my solution from here there. Easy kill. However I was first surprised to note the extra test cases and then got very soon humbled by the fact that it did not make full score there.
I had to put in some extra work to get some undetected bugs out. It also needed extra optimization.
Test case#14 has wrong set of test case, I submitted two time and finally checked the test case, please someone correct that:
passwords:
arli eqe ndmc nhog oqt xih zt
check string:
xiheqexiheqeoqtxihoqtarlixihxihoqtndmcxihxihnhogeqeztndmcoqteqeeqezteqexihztnhogndmcarlinhogztndmcztztxihxihnhogndmcndmcnhogarlixihztarlinhogoqtnhogoqtnhogztztndmcxihoqtnhognhognhogztnhogndmcarlieqeoqtztarliarlioqtnhogndmcoqtarlindmcndmcoqtnhogxiheqeoqtarlioqtnhogarlioqteqeoqtxihnhogxihxihztarlinhogarlindmcnhogxihnhogxihndmcxihnhogarrzfv
it is valid but the result shows "WRONG PASSWORD".
Please can check test#5 and 9 as well.
In the event that there's more than one way to split the string: should we choose the option with the fewest components, the one which begins with the shortest component, or follow some other rule?