Mercurial > repos > icfp2014
view code/grid.lm @ 51:a482086958e1
merge
author | William Morgan <billjunk@mrgn.org> |
---|---|
date | Sun, 27 Jul 2014 13:52:32 -0700 |
parents | 57a4bddadd46 |
children | d087d0b28039 |
line wrap: on
line source
#{ import: [ length reverse split:at map fold:with filter flatten ] from: (module: "ll.lm") import: [ makeTree:size makeTree get:fromTree:size get:fromTree treeMap:size treeMap tree:size:update:with tree:update:with tree:set:to ] from: (module: "tree.lm") grid:get <- :grid :pos { x <- pos value y <- pos tail get: x fromTree: (get: y fromTree: grid) } grid:update:with <- :grid :pos :fun { x <- pos value y <- pos tail tree: grid update: y with: :row { tree: row update: x with: fun } } grid:set:to <- :grid :pos :val { grid: grid update: pos with: :el { val } } gridMaxY <- :grid {grid value} gridMaxX <- :grid {(get: 0 fromTree: grid) value} gridArea <- :grid {(grid gridMaxX) * (grid gridMaxY)} grid:inBounds? <- :grid :pos { x <- pos value y <- pos tail maxY <- (grid gridMaxY) maxX <- (grid gridMaxX) ((x >= 0) + (y >= 0) + (x < maxX) + (y < maxY)) > 0 } calcPos <- :move from { x <- from value y <- from tail if: move { if: move = 1 { x <- x + 1 } else: { if: move = 2 { y <- y + 1 } else: { x <- x - 1 } } } else: { y <- y - 1 } #[x y] } }