changeset 36:c42d3c8b1d75

problem response json is parsed, also works with training problems. tested.
author William Morgan <bill@mrgn.org>
date Sat, 10 Aug 2013 23:30:12 -0700
parents 9d5c3b078c78
children 1dcf26c070fe 4750da71cae6
files src/requests.tp
diffstat 1 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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)
+			
 		}
 	}
 }