Sort by

recency

|

71 Discussions

|

  • + 0 comments

    My ugly haskell code...

    getIntOnLine :: IO Int getIntOnLine = getLine >>= (\s -> return (read s :: Int))

    getEntryAmount :: IO Int getEntryAmount = getIntOnLine

    getTupleAmount :: Int -> IO [(Int, Int)] getTupleAmount x | x == 0 = return [] | x > 0 = getIntOnLine >>= (getTuples x) >>= (printResult x) >>= getTupleAmount

    checkSingleItem :: [(Int, Int)] -> [(Int, Int)] -> Bool checkSingleItem part whole = case part of [] -> True ((a,_):rest) -> (areAllTuplesEqual $ filter ((== a) .fst) whole) && (checkSingleItem rest whole)

    containsSingleElem :: [(Int, Int)] -> Bool containsSingleElem x = do let result = checkSingleItem x x result

    areAllTuplesEqual :: Eq a => [(a, a)] -> Bool areAllTuplesEqual [] = True -- An empty list trivially has all tuples "equal" areAllTuplesEqual (x:xs) = all (== x) xs

    printResult :: Int -> [(Int, Int)] -> IO Int printResult x y = do let z = (containsSingleElem y) if z then putStrLn "YES" else putStrLn "NO" return (x - 1)

    getTuples :: Int -> Int -> IO [(Int, Int)] getTuples x y | y > 0 = do z <- getLine let v = (map (\m -> read m :: Int) (words z)) let b = (case v of [u, i] -> (u, i) _ -> (-1, -1)) let s = (do r <- (getTuples x (y - 1)) return ([b] ++ r)) s | y == 0 = return []

    main :: IO () main = do getEntryAmount >>= getTupleAmount return ()

  • + 0 comments

    It’s such a helpful way to start understanding the core ideas—like how pure functions behave, and why immutability matters. 11 x play

  • + 0 comments

    Discover premium car rental services with Royals Rent a Car Lahore. From luxury vehicles like Land Cruisers, Fortuners, and limousines to affordable intercity travel. Royal Motors

  • + 0 comments

    Functions are a must if you want clean, reusable code! When we worked on reelit com, they saved us tons of time by keeping everything organized and efficient.

  • + 0 comments

    When looking at a set of ordered pairs, Lead Generation Accountants may consider whether each unique value in the domain maps to a single value in the range to determine if it's a valid function. For each test case, check that no domain value repeats.