News for hackers. Stuff that matters.
Re:Most candidates cannot solve this interview problem by hyperrealgopher on Sunday February 07, 2021 @02:29AM (#26053343)
Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match!

https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

Re:Most candidates cannot solve this interview problem by zzo38computer on Sunday February 07, 2021 @02:53AM (#26053418)
My own first idea was actually similar to yours, although I wrote:

  map (head &&& length) . group
(Also, it took me only a few seconds, because it just seemed obvious to me, even though Haskell is not the programming language I normally use for my projects, but it seems the right thing for this.)
Re:Most candidates cannot solve this interview problem by hyperrealgopher on Sunday February 07, 2021 @03:15AM (#26053506)
Ha, what a coincidence! Right before you posted this I just remembered (&&&) exists: https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

Thanks for sharing!

Re:Most candidates cannot solve this interview problem by solresol on Sunday February 07, 2021 @02:43AM (#26053394)
> module Main where

> input = "aaaabbbcca"

> r :: String -> (Char,Int) -> [(String, Int)]

> r [] (c,n) = [([c],n)]

> r (x:xs) (c,n)

> | c == x = r xs (c,n+1)

> | otherwise = (([c],n): r xs (x,1))

> main = putStrLn (show (r (tail input) (head input, 1) ))

4 minutes 42 seconds.

And no, I don't write code like this normally, but I guess this is me when I'm under time pressure... anyway, I could refactor it nicely afterwards in the 25 minutes allocated.

Re:Most candidates cannot solve this interview problem by hyperrealgopher on Sunday February 07, 2021 @03:15AM (#26053510)
Great solution that avoids using any functions that do the heavy lifting for you! Thanks for showing!