Created
November 26, 2017 20:50
-
-
Save maruks/18fb2a23e1a2d019dc37563aa08ee46f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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