Sort by

recency

|

20 Discussions

|

  • + 0 comments

    Haskell

    module Main where
    
    import qualified Data.Map as M
    
    missingNumbers :: [Int] -> [Int] -> [Int]
    missingNumbers xs ys = do
        let mx = M.fromListWith (+) $ zip xs $ repeat 1
        let my = M.fromListWith (+) $ zip ys $ repeat 1
        let diff = M.differenceWith (\y x -> if x == y then Nothing else Just (y - x)) my mx
        M.keys diff
    
    main :: IO ()
    main = do
        _ <- getLine
        xs <- fmap (map read . words) getLine
        _ <- getLine
        ys <- fmap (map read . words) getLine
        let result = missingNumbers xs ys
        putStrLn $ unwords $ map show result
    
  • + 0 comments

    F#

    stdin.ReadLine()
    let A = stdin.ReadLine().Split()|> Array.countBy id
    stdin.ReadLine()
    
    stdin.ReadLine().Split()|> Array.countBy id
    |> Array.except A
    |> Array.map fst
    |> Array.sort
    |> String.concat " "
    |> printfn "%s"
    
  • + 0 comments

    f# solution

    open System
    
    let getCount key s =
        match Seq.tryFind (fun (k, _) -> k = key) s with
        | Some(_, values) -> Seq.length values
        | None -> 0
    
    let _ = Console.ReadLine()
    let left = Console.ReadLine() |> (fun s -> s.Split(" "))
    let _ = Console.ReadLine()
    let right = Console.ReadLine() |> (fun s -> s.Split(" "))
    
    let groupLeft = left |> Seq.groupBy id
    let groupRight = right |> Seq.groupBy id
    
    Seq.append left right
    |> Seq.distinct
    |> Seq.filter (fun key ->
        (getCount key groupLeft) <> getCount key groupRight)
    |> List.ofSeq
    |> Seq.sort
    |> String.concat " "
    |> Console.WriteLine
    
  • + 0 comments

    haskell

    import Data.List (intercalate)
    import Data.Array (accumArray, elems)
    
    counts l u xs = accumArray (+) 0 (l, u) [(x, 1) | x <- xs]
    
    missing l u xs ys =
      let cx = elems $ counts l u xs
          cy = elems $ counts l u ys
        in [i | (i, a, b) <- zip3 [l..] cx cy, a < b]
    
    main = do
      getLine
      lx <- getLine
      getLine
      ly <- getLine
      let xs = map read $ words lx :: [Int]
          ys = map read $ words ly :: [Int]
          l = min (minimum xs) (minimum ys)
          u = max (maximum xs) (maximum ys)
      putStrLn $ intercalate " " $ map show $ missing l u xs ys
    
  • + 0 comments

    Scala:

    object Solution {
        import scala.io.StdIn.{readInt, readLine}
    
        def main(args: Array[String]): Unit = {
            val A = readList
            val B = readList
            println(missingVals(A, B).sorted.mkString(" "))
        }
    
        def readList: List[Int] = {
            val _ = readInt
            readLine.split(' ').map(_.toInt).toList
        }
    
        def missingVals[T](A: List[T], B: List[T]): List[T] = {
            val (mapA, mapB) = (countMap(A), countMap(B))
            (mapA.keySet | mapB.keySet)
                .filterNot(n => mapA(n) == mapB(n))
                .toList
        }
    
        def countMap[T](l: List[T]): Map[T, Int] = {
            val m = Map.empty[T, Int].withDefaultValue(0)
            l.foldLeft(m)((m, e) => m + (e -> (m(e) + 1)))
        }
    }