Sort by

recency

|

7 Discussions

|

  • + 0 comments

    this was easy, scala:

    import scala.io.StdIn
    
    object Solution {
      private val wrongPassword = "WRONG PASSWORD"
    
      private def validateLogin(loginAttempt: String, passwords: Seq[String]): String = {
        def parse(remaining: String): Option[Seq[String]] = {
          if (remaining.isEmpty)
            return Some(Nil)
          passwords
            .find(remaining.startsWith)
            .flatMap { token => parse(remaining.substring(token.length)).map(token +: _) }
        }
        parse(loginAttempt)
          .map(_.mkString(" "))
          .getOrElse(wrongPassword)
      }
    
      def main(args: Array[String]): Unit = {
        val in = Iterator
          .continually(StdIn.readLine())
          .takeWhile(null != _)
          .map(_.trim)
        val t = in.next().toInt
        (1 to t)
          .map { _ =>
            val n = in.next().toInt
            val passwords = in.next().split(' ').toSeq
            val loginAttempt = in.next()
            validateLogin(loginAttempt, passwords)
          }
          .foreach(println)
      }
    }
    
  • + 1 comment

    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

  • + 0 comments

    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.

  • + 0 comments

    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.

  • + 1 comment

    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?