comparison src/requests.tp @ 41:4750da71cae6

parsing myproblems.json, needs fix
author William Morgan <bill@mrgn.org>
date Sun, 11 Aug 2013 02:16:55 -0700
parents c42d3c8b1d75
children e9e01cd64993
comparison
equal deleted inserted replaced
36:c42d3c8b1d75 41:4750da71cae6
176 } else: { 176 } else: {
177 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} 177 #{print <- print: "HTTP response gave error! code was: " . _code . "\n"}
178 } 178 }
179 } 179 }
180 180
181 problem <- :bod { 181 _problem <- :decoded {
182 decoded <- json decode: bod
183 #{ 182 #{
184 id <- decoded get: "id" withDefault: -1 183 id <- decoded get: "id" withDefault: -1
185 size <- decoded get: "size" withDefault: -1 184 size <- decoded get: "size" withDefault: -1
186 operators <- decoded get: "operators" withDefault: #[] 185 operators <- decoded get: "operators" withDefault: #[]
187 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j 186 //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j
199 print: string . "\n" 198 print: string . "\n"
200 } 199 }
201 } 200 }
202 } 201 }
203 202
203 problem <- :bod {
204 decoded <- json decode: bod
205 _problem: decoded
206 }
207
208 problems <- :bod {
209 decoded <- json decode: bod
210 decoded map: :idx el{
211 _problem: el
212 }
213 }
214
204 main <- :args { 215 main <- :args {
216 print: "Program Start."
205 testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder. 217 testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder.
206 testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder. 218 testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder.
207 someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}" 219 someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}"
208 someProgram <- "(lambda (input) (shl1 input))" 220 someProgram <- "(lambda (input) (shl1 input))"
209 221
210 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" 222 //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n"
211 //print: ((guess: "someId" "someProg") string) . "\n" 223 //print: ((guess: "someId" "someProg") string) . "\n"
212 print: ((problem: someProblem) string) . "\n" 224 //print: ((problem: someProblem) string) . "\n"
225
226 file <- os open: "/home/wbm25/Desktop/icfp2013/data/myproblems.json" (os O_RDONLY)
227 fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems...
228 os close: file
229
230 print: (((problems: fstr) get: 0) string )
231
232
213 233
214 if: (args length) > 1 { 234 if: (args length) > 1 {
215 key <- args get: 1 235 key <- args get: 1
216 236
217 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) 237 //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key)
218 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) 238 //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key)
219 print: ((guess: testId0 someProgram) sendWithKey: key) 239 //print: ((guess: testId0 someProgram) sendWithKey: key)
220 240 println: "derp"
221 } 241 }
222 } 242 }
223 } 243 }