Mercurial > repos > icfp2013
comparison src/bv.tp @ 9:0ccebdbc3e80
Add support for generating programs that contain fold. Make the desired program size a command line argument.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 09 Aug 2013 01:17:14 -0700 |
parents | 3f0172ceab81 |
children | 655d5b19333d |
comparison
equal
deleted
inserted
replaced
8:3f0172ceab81 | 9:0ccebdbc3e80 |
---|---|
114 } | 114 } |
115 | 115 |
116 fold:with:startingAt <- :toFold :fun :startAcc { | 116 fold:with:startingAt <- :toFold :fun :startAcc { |
117 #{ | 117 #{ |
118 string <- { | 118 string <- { |
119 "(fold " . (string: toFold) . " " . (string: startAcc) . "(lambda (val acc) " . (string: fun) . "))" | 119 "(fold " . (string: toFold) . " " . (string: startAcc) . " (lambda (val acc) " . (string: fun) . "))" |
120 } | 120 } |
121 eval <- { | 121 eval <- { |
122 _acc <- (eval: startAcc) | 122 _acc <- (eval: startAcc) |
123 source <- (eval: toFold) | 123 source <- (eval: toFold) |
124 //parser doesn''t currently like vertical whitespace in arays so | 124 //parser doesn''t currently like vertical whitespace in arays so |
160 | 160 |
161 //TODO: memoize this to improve runtime for large n | 161 //TODO: memoize this to improve runtime for large n |
162 allOfSize:inFold? <- :n :infold? { | 162 allOfSize:inFold? <- :n :infold? { |
163 if: n = 1 { | 163 if: n = 1 { |
164 res <- #[one zero input] | 164 res <- #[one zero input] |
165 if: infold? { | 165 if: infold? = 2 { |
166 res append: acc | 166 res append: acc |
167 res append: val | 167 res append: val |
168 } | 168 } |
169 res | 169 res |
170 } else: { | 170 } else: { |
211 } | 211 } |
212 numMid <- numMid + 1 | 212 numMid <- numMid + 1 |
213 } | 213 } |
214 numLeft <- numLeft + 1 | 214 numLeft <- numLeft + 1 |
215 } | 215 } |
216 if: n > 4 && infold? = 0 { | |
217 numSeq <- 1 | |
218 limitSeq <- n - 3 | |
219 while: { numSeq < limitSeq } do: { | |
220 numFun <- 1 | |
221 limitFun <- n - (2 + numSeq) | |
222 while: { numFun < limitFun } do: { | |
223 numStart <- n - (2 + numSeq + numFun) | |
224 choicesStart <- (allOfSize: numStart inFold?: 1) | |
225 choicesFun <- (allOfSize: numFun inFold?: 2) | |
226 foreach: (allOfSize: numSeq inFold?: 1) :idx seqExp { | |
227 foreach: choicesFun :idx funExp { | |
228 foreach: choicesStart :idx startExp { | |
229 res append: (fold: seqExp with: funExp startingAt: startExp) | |
230 } | |
231 } | |
232 } | |
233 numFun <- numFun + 1 | |
234 } | |
235 numSeq <- numSeq + 1 | |
236 } | |
237 } | |
216 } | 238 } |
217 } | 239 } |
218 res | 240 res |
219 } | 241 } |
220 } | 242 } |
221 | 243 |
222 allOfSize <- :n { | 244 allOfSize <- :n { |
223 allOfSize: (n - 1) inFold?: false | 245 allOfSize: (n - 1) inFold?: 0 |
224 } | 246 } |
225 } | 247 } |
226 } | 248 } |
227 | 249 |
228 test <- :prog { | 250 test <- :prog { |
233 foreach: vals :idx val { | 255 foreach: vals :idx val { |
234 print: "p(0x" . (hex: val) . ") = 0x" . (hex: (prog run: val)) . "\n" | 256 print: "p(0x" . (hex: val) . ") = 0x" . (hex: (prog run: val)) . "\n" |
235 } | 257 } |
236 } | 258 } |
237 | 259 |
238 main <- { | 260 main <- :args { |
239 test: (program gentestprog) | 261 test: (program gentestprog) |
240 test: (program exampleprog) | 262 test: (program exampleprog) |
241 prog <- program | 263 size <- 3 |
242 foreach: (prog allOfSize: 5) :idx tree { | 264 if: (args length) > 1 { |
243 prog root! tree | 265 size <- int32: (args get: 1) |
244 test: prog | 266 } |
245 } | 267 if: size >= 2 { |
268 prog <- program | |
269 foreach: (prog allOfSize: size) :idx tree { | |
270 prog root! tree | |
271 test: prog | |
272 } | |
273 } | |
274 0 | |
246 } | 275 } |
247 } | 276 } |