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
39foldlMeanStddev = meanAndStddev Array.foldl
42customFoldrMeanStddev = meanAndStddev myFoldr
45customFoldlMeanStddev = meanAndStddev myFoldl
53updateNRandomIndices f indexList startList =
55 (\ i oldList -> updateN i f oldList)
59randomLookups : List Int -> Array.Array Float -> List (Maybe Float)
60randomLookups indices arr =
61 List.map (\i -> Array.get i arr) indices
64myFoldl : (a -> b -> b) -> b -> Array.Array a -> b
67 len = Array.length arr
73 helper (f (fromJust <| Array.get i arr) init) (i+1)
77myFoldr : (a -> b -> b) -> b -> Array.Array a -> b
80 len = Array.length arr
86 helper (f (fromJust <| Array.get i arr) init) (i-1)
87 in helper init (len-1)
90updateN : Int -> (a -> a) -> Array.Array a -> Array.Array a
92 case Array.get n arr of
93 Just x -> Array.set n (f x) arr
94 _ -> 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