5import Debug exposing (crash)
14randomArray gen n initSeed =
18 (nextToAdd, newSeed) = Random.generate gen seed
19 newAccum = Array.push nextToAdd accum
20 in (newSeed, newAccum)
22 snd <| List.foldl f (initSeed, Array.empty) [1 .. n]
25 : ((Float -> (Float, Float) -> (Float, Float)) -> (Float, Float) -> Array.Array Float -> (Float, Float))
28meanAndStddev foldFn ourArray =
30 --ourArray = randomArray n (Random.initialSeed 23)
31 (theSum, sumSq) = foldFn (\x (sum, sumSq) -> (x + sum, (x^2) + sumSq) ) (0,0) ourArray
33 (theSum, sqrt(theSum*theSum - sumSq))
36foldrMeanStddev = meanAndStddev Array.foldr
38foldlMeanStddev = meanAndStddev Array.foldl
40customFoldrMeanStddev = meanAndStddev myFoldr
42customFoldlMeanStddev = meanAndStddev myFoldl
49updateNRandomIndices f indexList startList =
51 (\ i oldList -> updateN i f oldList)
55randomLookups : List Int -> Array.Array Float -> List (Maybe Float)
56randomLookups indices arr =
57 List.map (\i -> Array.get i arr) indices
61myFoldl : (a -> b -> b) -> b -> Array.Array a -> b
64 len = Array.length arr
70 helper (f (fromJust <| Array.get i arr) init) (i+1)
74myFoldr : (a -> b -> b) -> b -> Array.Array a -> b
77 len = Array.length arr
83 helper (f (fromJust <| Array.get i arr) init) (i-1)
84 in helper init (len-1)
86updateN : Int -> (a -> a) -> Array.Array a -> Array.Array a
88 case Array.get n arr of
89 Just x -> Array.set n (f x) arr
90 _ -> crash "Array out of bounds"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list