# HG changeset patch # User William Morgan # Date 1376202612 25200 # Node ID c42d3c8b1d759e6c9f064898a0d2254113d12b8a # Parent 9d5c3b078c78aa9f819751718021682bff567ded problem response json is parsed, also works with training problems. tested. diff -r 9d5c3b078c78 -r c42d3c8b1d75 src/requests.tp --- a/src/requests.tp Sat Aug 10 22:31:18 2013 -0700 +++ b/src/requests.tp Sat Aug 10 23:30:12 2013 -0700 @@ -178,25 +178,46 @@ } } - problem <- : str { - + problem <- :bod { + decoded <- json decode: bod + #{ + id <- decoded get: "id" withDefault: -1 + size <- decoded get: "size" withDefault: -1 + operators <- decoded get: "operators" withDefault: #[] + //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j + timeLeft <- decoded get: "timeLeft" withDefault: 301 + // training problems have a challenge, real ones do not.: + challenge <- decoded get: "challenge" withDefault: "" + string <- { + str <- "problem '" . id . "' has size '" . size . "' and operators:" + foreach: operators :idx val { + str <- str . "\n " . (string: idx) . ": " . val + } + str . "\ntimeLeft: " . timeLeft + } + print <- { + print: string . "\n" + } + } } main <- :args { + testId0 <- "wdThP1AgVrS2rp7q6qt9mLqp" // TRAINING PROGRAM ID! not real one. response in data folder. + testId1 <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM ID! not real one. response in data folder. + someProblem <- "{\"id\":\"QwhG7ZpaVsfXiLRvbJfIfxl8\",\"size\":15,\"operators\":[\"and\",\"if0\",\"shl1\",\"shr16\",\"tfold\"]}" + someProgram <- "(lambda (input) (shl1 input))" + //print: ((evalId: "someId" #[1u64 2u64 3u64]) string) . "\n" //print: ((guess: "someId" "someProg") string) . "\n" + print: ((problem: someProblem) string) . "\n" if: (args length) > 1 { key <- args get: 1 - testId <- "wdThP1AgVrS2rp7q6qt9mLqp" // my first training problem - someId <- "QwhG7ZpaVsfXiLRvbJfIfxl8" // TRAINING PROGRAM IDs!!! not real ones. - - someProgram <- "(lambda (input) (shl1 input))" //print: ((evalProgram: "(lambda (input) (shl1 input))" #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) - //print: ((evalId: testId #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) - print: ((guess: testId someProgram) sendWithKey: key) - + //print: ((evalId: testId0 #[1u64 0xEFFFFFFFFFFFFFu64]) sendWithKey: key) + print: ((guess: testId0 someProgram) sendWithKey: key) + } } }