✡ must compute arithmetic average of a list ✡ only one pass is allowed ✡ constant memory
Name:
Anonymous2015-07-08 17:54
The back-story is that some guy in Kyiv asked this question during interviews with about twenty different Haskellers, and not a single one of them was able to solve it correctly.
>>7 I did that because: ✡ only one pass is allowed
Name:
Anonymous2015-07-09 17:28
<-------------- *** CHECK MY DUBS!!!!!! ***
Name:
Anonymous2015-07-09 18:20
✡
Google interview, eh?
Name:
Anonymous2015-07-10 4:59
Haskell constant memory
/0
Name:
Anonymous2015-07-10 17:39
{-# LANGUAGE BangPatterns #-} mean :: (Num a, Fractional a) => [a] -> a mean xs = go xs 0 0 where go (x:xs) !s !n = go xs (s+x) (n+1) go [] !s !n = s / n
main = print $ mean [1..3000000]
GHC's profiling tools tell me this uses constant memory.
>>31 is it common for haskell programmers to make heaps of typos? second one I saw in two days
and how come there's so many retarded names in haskell? like they're too lazy to spell "first" and "second", yet they write shit like "putStrLn"
the whole thing looks like it was written by a bunch of camels who forgot how to fuck and are desperately trying to seduce a female camel with symbols, which is probably quite accurate if you replace 'camel' with 'human'.
>>39 The average of an arbitrary infinite list cannot be computed in general. How can you know what terms arbitrarily far out in the sequence will do in a finite amount of computations without ``knowing'' the sequence symbolically?