Skip to content

Instantly share code, notes, and snippets.

@maruks
Created November 26, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maruks/18fb2a23e1a2d019dc37563aa08ee46f to your computer and use it in GitHub Desktop.
Save maruks/18fb2a23e1a2d019dc37563aa08ee46f to your computer and use it in GitHub Desktop.
blur : Dict(Int,Int) Int -> ( Int, Int ) -> Int
blur cells ( x, y ) =
let
xs =
range (x - 1) (x + 1)
ys =
range (y - 1) (y + 1)
points =
concatMap (\x -> map (\y -> ( x, y )) ys) xs
( sum, num ) =
foldr
(\p ( s, n ) ->
case Dict.get p cells of
Just h ->
( sum + h, num + 1 ) -- ( s + h, n + 1 )
Nothing ->
( s, n )
)
( 0, 0 )
points
in
sum // num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment