✡ 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?
Name:
Anonymous2015-07-15 8:47
In perl6:
my $result = [+]@list / @list;
Are you guys even trying?
Name:
Anonymous2015-07-15 8:50
Oops, forgor precedence rules.
( [+] @list ) / @list
This works
Name:
Anonymous2015-07-15 16:52
>>40 Ah but you see, maths is not limited to execution of programs. An inductive argument from the algorithm's formal representation, and another relating it to its implementation, is sufficient to prove correctness of the algorithm and the program code. In practice we'd add tests to an arbitrary (small) subset of ∞, and some tool-driven coverage analysis.
That being said, the weight of that critique is on the case of the zero-element list. One might counter that it's appropriate to leave the average of nothing undefined, but thass' just some sloppy-ass whack right thur as far as pretending to do proper engineering goes.
The subset would be small and trivial enough to be impractical to test.
Static typing is a pseudoscience, related to perpetual motion, which is real only in theory
Name:
Anonymous2015-07-16 7:32
It is a truth universally acknowledged that almost all mathematicians are Platonists, at least when they are actually doing mathematics …" This refers to their implicit embrace of essentialism, which he finds revealed in mathematicians peculiar use of language. Whereas physicists define Lie algebra as a rule they can apply to facts, mathematicians define it as an essence of a structure, independent of any circumstance.
It is a truth universally acknowledged that almost all type-theoreticians are Pederasts, at least when they are actually doing type theory …" This refers to their implicit embrace of homosexualism, which he finds revealed in type theory peculiar use of language. Whereas heterosexuals define sex as a rule they can apply to reproduction, type-theoreticians define it as an essence of a structure, independent of any circumstance.
>>47 Kike theory is made up bullshit. The age-old practice of inventing new unscientific "ideologies" that can change on a whim is still alive and well.