New answers tagged

0

Disclaimer: I don't know Haskell and I have never used it before. solve low hi = length . takeWhile (<= hi) . dropWhile (< low) . map read . filter (allF [hasDouble, noLeadingZeros]) $ combinations 6 ['0'..'9'] where hasDouble = any ((== 2) . length) . group noLeadingZeros = (/= '0') . head Instead of running combinations 6 ['0'..'9'] and ...


4

Perhaps you could wrap bare Sockets in an auxiliary datatype that enabled buffering. Something like: data BufferedSocket = BufferedSocket [ByteString] Socket Then you could define your own recv function like recv :: BufferedSocket -> Int -> IO (BufferedSocket,ByteString) which looked at the buffer before actually trying to read data from the socket....


1

// is best called with one bulk list because each call incurs one O(n) array copy. Folds over iterates when you need an index and know its range, it's like for vs. while. drawCanvas :: Canvas -> IO () drawCanvas = putStrLn . unlines . map (map snd) . DL.groupBy ((==) `DF.on` fst . fst) . DA.assocs mkSierpinski :: Int -> Int -> Canvas ...


3

First, let me ungolf and simplify your code slightly, so it will be easier for me to read: import System.Random pick :: Int -> [a] -> (a,[a]) pick 0 (x:xs) = (x, xs) pick i (x:xs) = let (y,ys) = pick (i-1) xs in (y, x:ys) pick _ [] = error "pick: Invalid index" shuffle :: [a] -> IO [a] shuffle lst = runner (length lst) lst ...


1

I am also on my way to dive deeper into Haskell and it turns out that I am going through the same learning path in Hackerank. If you'd like to, I made a much shorter solution that still requires minor fixes but works with any height, width (2*height-1) and depth level. I still didn't figure out where does reside the problem yet in my code (works fine with ...


2

Note that, if you just remove the tag Response from all your types (including unifying the types CoordinateResponse and Coordinate which seem like they ought to be a single type), it's already a lot more readable: toCoordinate :: Geo -> Coordinate toCoordinate (Geo (Result [Location coord]:_)) = coord toCoordinate _ = Coordinate 0 0 Also, the Location ...


3

It would be more usual to replace the if null strings... conditional with a case, and concat is more commonly used than fold for lists: fizzbuzz :: [Fizzrule] -> Int -> String fizzbuzz rules int = case mapMaybe (processrule int) rules of [] -> show int strings -> concat strings Similarly, processrule would more commonly be written ...


Top 50 recent answers are included