Mercurial > repos > icfp2014
annotate code/mike00.lm @ 15:4bc308c03952
Fix argument passing to main
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 25 Jul 2014 21:06:22 -0700 |
parents | ce68c8a607ee |
children | 89aa6d3165ee |
rev | line source |
---|---|
14
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 length <- :lst { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 len <- [] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 while: { not: (lst isInteger?)} do: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 lst <- lst tail |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 len <- len + 1 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 len |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 reverse <- :lst { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 new <- [] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 while: { not: (lst isInteger?)} do: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 new <- (lst value) | new |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 lst <- lst tail |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 new |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 split:at <- :lst :pos { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 first <- [] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 i <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 while: { i < pos } do: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 first <- (lst value) | first |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 lst <- lst tail |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 i <- i + 1 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #[(reverse: first) lst] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 map <- :lst fun { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 new <- [] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 while: { not: (lst isInteger?) } do: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 new <- (fun: (lst value)) | new |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 lst <- lst tail |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 reverse: new |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 makeTree <- :lst size { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 ret <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 sub <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 half <- size / 2 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 if: size = 2 { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 ret <- #[(lst value) ((lst tail) value)] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 } else: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 if: size = 1 { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 ret <- lst |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 } else: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 sub <- split: lst at: half |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 ret <- #[ |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 (makeTree: (sub value) half) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 (makeTree: (sub tail) size-half) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 ] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 ret |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 get:fromTree:size <- :idx :tree :size { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 ret <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 half <- size / 2 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 if: size <= 2 { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 if: idx = 0 { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 ret <- tree value |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 } else: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 ret <- tree tail |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 } else: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 if: idx < half { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 ret <- get: idx fromTree: (tree value) size: half |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 } else: { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 ret <- get: idx-half fromTree: (tree tail) size: size-half |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 ret |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 height <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 width <- 0 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 main <- { |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 /* map <- initWorld value |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 height <- map length |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 width <- (map value) length |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 */ |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 lst <- [1 2 3 4 5 6 7 8 9] |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 print: (length: lst) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 print: (map: lst :el { el + 1 }) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 print: (split: lst at: (length: lst) / 2) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 tree <- makeTree: lst (length: lst) |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 print: tree |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 } |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 |
ce68c8a607ee
Added a new file for experimenting with some helper functions
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 } |