Mercurial > repos > icfp2013
changeset 46:e9e01cd64993
Fix decoding of JSON problem array
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Aug 2013 02:32:06 -0700 |
parents | b90ccee0bace |
children | c55d4271bb77 |
files | src/requests.tp |
diffstat | 1 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/requests.tp Sun Aug 11 02:18:55 2013 -0700 +++ b/src/requests.tp Sun Aug 11 02:32:06 2013 -0700 @@ -120,7 +120,7 @@ } } else: { #{print <- print: "HTTP response gave error! code was: " . _code . "\n"} - + } } @@ -179,15 +179,20 @@ } _problem <- :decoded { + _id <- decoded get: "id" withDefault: -1 + _size <- decoded get: "size" withDefault: -1 + _ops <- decoded get: "operators" withDefault: #[] + _timeLeft <- decoded get: "timeLeft" withDefault: 301 + _challenge <- decoded get: "challenge" withDefault: "" #{ - id <- decoded get: "id" withDefault: -1 - size <- decoded get: "size" withDefault: -1 - operators <- decoded get: "operators" withDefault: #[] + id <- { _id } + size <- { _size } + operators <- { _ops } //solved <- decoded get: "solved" withDefault: false // todo: B ool up ean this son of a j - timeLeft <- decoded get: "timeLeft" withDefault: 301 + timeLeft <- { _timeLeft } // training problems have a challenge, real ones do not.: - challenge <- decoded get: "challenge" withDefault: "" - string <- { + challenge <- { _challenge } + string <- { str <- "problem '" . id . "' has size '" . size . "' and operators:" foreach: operators :idx val { str <- str . "\n " . (string: idx) . ": " . val @@ -207,7 +212,7 @@ problems <- :bod { decoded <- json decode: bod - decoded map: :idx el{ + decoded map: :el{ _problem: el } } @@ -223,7 +228,7 @@ //print: ((guess: "someId" "someProg") string) . "\n" //print: ((problem: someProblem) string) . "\n" - file <- os open: "/home/wbm25/Desktop/icfp2013/data/myproblems.json" (os O_RDONLY) + file <- os open: "data/myproblems.json" (os O_RDONLY) fstr <- (os read: file 400 * 1024) // file was 276k before bonus problems... os close: file