# Measure Smoothing in CF

Sep 10th, 2020 (edited)
882
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. get_measures :: Num, IO ->> [Num]
2. x ~> do:
3.     return [Num IO.raw_input "" for _ in [0..x]]
4.
5. dist :: Num, Num ->> Num
6. x, y | x == y => 0
7. x, y => abs(x - y)
8.
9. in_bounds :: Num, Num, Num ->> Num
10. x, y, b => dist x y < b
11.
12. check :: Num, [Num], Maybe Int ->> Bool
13. dmax, arr, Nothing => _check 0
14. _, arr, idx | idx == length arr - 1 => True
15. dmax, arr, idx => in_bounds arr[idx] arr[idx+1] ? _check idx+1 : False
16. where _check = check dmax arr
17.
18. smooth_measures :: [Num], Maybe Int ->> [Num]
19. arr, Nothing => _smooth 0
20. arr, x | x == 0 => [arr[0], ... _smooth 1]
21. arr, x | x == length arr => arr[-1]
22. arr, x => [(arr[x - 1] + arr[x + 1]) / 2, ... _smooth x + 1]
23. where _smooth = smooth arr
24.
25. do:
26.     nbMeasures = IO.raw_input ""
27.     diffMax = IO.raw_input ""
28.     measures = Mut get_measures nbMeasures
29.
30.     cnt = Mut 0
31.     while not check diffMax measures:
32.         measures = smooth_measures measures Nothing
33.         ++cnt
34.
35.     IO.log <- cnt
36.
RAW Paste Data