<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Feb 21, 2015 at 4:50 PM, Joel Neely <span dir="ltr"><<a href="mailto:joel.neely@gmail.com" target="_blank">joel.neely@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-family:georgia,serif;font-size:small">Given a list of fractional numbers, produce a smoothed list, where each value is averaged with its immediate neighbors (except the first and last, which fail to have both neighbors), as shown below.</div><div style="font-family:georgia,serif;font-size:small"><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">[0.0,4.0,2.0,6.0,1.0,2.0]</font></div><div><font face="monospace, monospace">[    2.0,4.0,3.0,3.0    ]</font></div></blockquote><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">It seems natural to my eye to express this as, "A list with at least three elements contributes a value to the result", as in:</font></div><div><font face="georgia, serif"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">smooth :: Fractional n => [n] -> [n]</font></div></div><div><div><font face="monospace, monospace">smooth (a:z@(b:c:_)) = (a + b + c) / 3 : smooth z</font></div></div><div><div><font face="monospace, monospace">smooth _             = []</font></div></div></blockquote><br></div></blockquote><div><br></div><div>In Haskell, I would write this with higher-order functions though :<br><br></div><div>smooth xs = zipWith3 (\a b c -> (a+b+c)/3) xs (drop 1 xs) (drop 2 xs)<br><br>-- <br></div><div>Jedaï<br></div></div><br></div></div>