Mercurial > repos > icfp2014
comparison code/dotScanner.lm @ 26:4f7a421e77c6
Tag teaming the continuation function
author | William Morgan <billjunk@mrgn.org> |
---|---|
date | Fri, 25 Jul 2014 23:19:29 -0700 |
parents | ec0b74f4f2d9 |
children | 75c97fb80602 |
comparison
equal
deleted
inserted
replaced
25:ec0b74f4f2d9 | 26:4f7a421e77c6 |
---|---|
163 } | 163 } |
164 | 164 |
165 tree:set:to <- :tree :idx :val { | 165 tree:set:to <- :tree :idx :val { |
166 tree: tree update: idx with: :el { val } | 166 tree: tree update: idx with: :el { val } |
167 } | 167 } |
168 | |
169 grid:get <- :grid :pos { | |
170 x <- pos value | |
171 y <- pos tail | |
172 get: x fromTree: (get: y fromTree: grid) | |
173 } | |
168 | 174 |
169 grid:update:with <- :grid :pos :fun { | 175 grid:update:with <- :grid :pos :fun { |
170 x <- pos value | 176 x <- pos value |
171 y <- pos tail | 177 y <- pos tail |
172 tree: grid update: y with: :row { | 178 tree: grid update: y with: :row { |
173 tree: row update: x with: fun | 179 tree: row update: x with: fun |
174 } | 180 } |
175 } | 181 } |
176 | 182 |
177 grid:set:to <- :grid :pos :val { | 183 grid:set:to <- :grid :pos :val { |
178 grid: grid update: pox with: :el { val } | 184 grid: grid update: pos with: :el { val } |
185 } | |
186 | |
187 grid:inBounds? <- :grid :pos { | |
188 x <- pos value | |
189 y <- pos tail | |
190 maxY <- grid value | |
191 maxX <- (get: 0 fromTree: grid) value | |
192 ((x >= 0) + (y >= 0) + (x < maxX) + (y < maxY)) > 0 | |
179 } | 193 } |
180 | 194 |
181 /* | 195 /* |
182 ListGet <- :cell idx { | 196 ListGet <- :cell idx { |
183 if: idx = 0 {cell value} else: { | 197 if: idx = 0 {cell value} else: { |
196 ListGet | 210 ListGet |
197 ... | 211 ... |
198 } | 212 } |
199 */ | 213 */ |
200 | 214 |
201 grid <- tree: ... | 215 visited <- 0 |
202 visited <- tree: ... | 216 /* |
203 | |
204 advancer <- :listOfTupsLams { | 217 advancer <- :listOfTupsLams { |
205 notdone <- 1 | 218 notdone <- 1 |
206 while: { notdone } do: { | 219 while: { notdone } do: { |
207 listOfLamTups <- fold: listOfLamTups [] with: :acc el{ | 220 listOfLamTups <- fold: listOfLamTups [] with: :acc el{ |
208 ret <- 0 | 221 ret <- 0 |
223 ret <- [(el tail)] | 236 ret <- [(el tail)] |
224 } | 237 } |
225 } | 238 } |
226 } | 239 } |
227 | 240 |
228 //splitter: target start | 241 } |
229 } | 242 */ |
230 splitter <- :target start{ | 243 |
231 | 244 calcPos <- :move from { |
245 x <- from value | |
246 y <- from tail | |
247 if: move { | |
248 if: move = 1 { | |
249 x <- x + 1 | |
250 } else: { | |
251 if: move = 2 { | |
252 y <- y + 1 | |
253 } else: { | |
254 x <- x - 1 | |
255 } | |
256 } | |
257 } else: { | |
258 y <- y - 1 | |
259 } | |
260 #[x y] | |
261 } | |
262 | |
263 makeContClos <- :grid myLoc path { | |
264 { | |
265 ret <- [] | |
266 move <- 0 | |
267 atpos <- 0 | |
268 if: (grid: grid inBounds?: myLoc) { | |
269 if: (grid: visited get: myLoc) { | |
270 } else: { | |
271 atpos <- grid: grid get: myLoc | |
272 if: (atpos = 2) + (atpos = 3) + (atpos = 4) { | |
273 ret <- #[1 (reverse: path)] | |
274 } else: { | |
275 visited <- grid: visited set: myLoc to: 1 | |
276 if: atpos { | |
277 move <- 0 | |
278 while: { move < 4 } do: { | |
279 ret <- (makeContClos: grid (calcPos: move myLoc) move | path) | ret | |
280 } | |
281 ret <- #[0 ret] | |
282 } else: {} | |
283 } | |
284 } | |
285 } else: {} | |
286 ret | |
287 } | |
232 } | 288 } |
233 | 289 |
234 //scanFor <- :target visited { | 290 //scanFor <- :target visited { |
235 //} | 291 //} |
236 counterLoad <- 4 | 292 counterLoad <- 4 |
239 lmState <- (world value) tail | 295 lmState <- (world value) tail |
240 myLoc <- (lmState tail) value | 296 myLoc <- (lmState tail) value |
241 | 297 |
242 | 298 |
243 visited <- treeMap: grid :el { 0 } | 299 visited <- treeMap: grid :el { 0 } |
244 visited <- tree: visited set: myLoc to: 1 | 300 /* |
301 cont <- { | |
302 if: (grid: grid get: myLoc | |
303 visited <- tree: visited set: myLoc to: 1 | |
304 */ | |
245 | 305 |
246 | 306 |
247 | 307 |
248 //myPos <- | 308 //myPos <- |
249 path <- [3 1 3 1] //scanFor: 2 3 [myPos] | 309 path <- [3 1 3 1] //scanFor: 2 3 [myPos] |