Arc Forumnew | comments | leaders | submitlogin
1 point by tokipin 5981 days ago | link | parent

flat should be useful here. eg:

  (def avg2 (lst)
      (avg (flat lst)))
though i'm away from the lab and can't verify it right now


2 points by fallintothis 5981 days ago | link

I thought at at first, but that won't produce the same answers. Take his test case:

  '(1 2 3 (3 4 5) (3 4 (1 2 3)))
Using the desired method, it's:

  (/ (+ 1
        2
        3
        (/ (+ 3 4 5) 3)
        (/ (+ 3 4 (/ (+ 1 2 3) 3)) 3))
     5) ;= 13/5
But by flattening the list, we get:

  (/ (+ 1 2 3 3 4 5 3 4 1 2 3) 11) ;= 31/11

-----

1 point by tokipin 5981 days ago | link

ah, didn't see the 'resolved' thingie

-----

2 points by offby1 5981 days ago | link

topkin's thingy doesn't give the same result. Try it and see.

-----