git.haldean.org ubik / b024656
more work on fixing pokemon.uk Haldean Brown 4 years ago
2 changed file(s) with 29 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
9797 }
9898 ?: filter (\x -> math:lte x 10) (Cons 10 (Cons 20 (Cons 0 Nil)))
9999 = (Cons 10 (Cons 0 Nil))
100
101 : length
102 ^ List a -> Number
103 = \l -> ? l {
104 . Nil => 0
105 . Cons * cdr => + 1 (length cdr)
106 }
107 ?: length Nil = 0
108 ?: length (Cons 1 Nil) = 1
109 ?: length (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) = 4
110
111 : reduce
112 ^ (b -> a -> b) -> b -> List a -> b
113 = \f acc l -> ? l {
114 . Nil => acc
115 . Cons car cdr => reduce f (f acc car) cdr
116 }
117 ?: reduce + 10 (Cons 20 (Cons 30 Nil)) = 60
118 ?: reduce (\str char -> concat str char) "" (Cons "a" (Cons "bc" Nil)) = "abc"
00 ~ ubik-tests/pokemon
1 ` list
1 ` *list
2 ` math
23
34 ^ IV = Good = Bad
45
2930 = \k b -> ? {
3031 . eq k 0 => Tree Nil
3132 . => Tree ({
32 : ivs = list:map (\num -> ? {
33 : ivs = map (\num -> ? {
3334 . math:lt num (good b) => Good
3435 . => Bad
35 }) (list:range 0 (n b))
36 ! list:map (\iv -> ? iv {
36 }) (range 0 (n b))
37 ! map (\iv -> ? iv {
3738 . Good => TreePair Good (make (- k 1) (sub-good b))
3839 . Bad => TreePair Bad (make (- k 1) (sub-bad b))
3940 }) ivs
4849 : prob ^ Tree -> Number -> Number
4950 = \tree i -> {
5051 : c = children tree
51 : nc = list:length c
52 : nc = length c
5253 ! (? c {
5354 . Nil => ? { . eq i 0 => 1 . => 0 }
54 . List * * =>
55 list:map
56 (\child -> * (* n (/ 1 nc)) (prob (tree child) (? child {
55 . Cons * * =>
56 reduce + 0 (map
57 (\child -> * (/ 1 nc) (prob (tree child) (? child {
5758 . TreePair * iv => ? iv {
5859 . Good => (- i 1)
5960 . Bad => i
6061 }
6162 })))
62 c
63 c)
6364 })
6465 }
6566