changeset 42:a8db0f4039aa

merge
author William Morgan <bill@mrgn.org>
date Sun, 11 Aug 2013 02:17:43 -0700
parents 4750da71cae6 (current diff) 1cadb591eef1 (diff)
children b90ccee0bace
files
diffstat 2 files changed, 95 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/train/IxVBHQTlzePZHljYiBdZLwKh.json	Sun Aug 11 02:17:43 2013 -0700
@@ -0,0 +1,10 @@
+{
+    "id": "IxVBHQTlzePZHljYiBdZLwKh",
+    "size": 6,
+    "operators": [
+        "not",
+        "shr4",
+        "xor"
+    ],
+    "challenge": "(lambda (x_4565) (xor (shr4 x_4565) (not 1)))"
+}
\ No newline at end of file
--- a/src/solver.tp	Sun Aug 11 02:16:55 2013 -0700
+++ b/src/solver.tp	Sun Aug 11 02:17:43 2013 -0700
@@ -9,6 +9,7 @@
 			#{
 				input <- { _val }
 				valmap <- { _dict }
+				allInputs <- { vals }
 				constantProgs <- { _const }
 				append <- :tree {
 					if: child? && (tree constant?) {
@@ -41,7 +42,7 @@
 					if: len = 0 && _hasFirst? {
 						len <- 1
 					}
-					len + _const length
+					len + (_const length)
 				}
 				printwithIndent <- :indent {
 					print: indent . "Input: " . (hex: _val) . "\n"
@@ -66,6 +67,35 @@
 				print <- {
 					printwithIndent: ""
 				}
+				findMatches:at <- :outputs :startIdx {
+					outVal <- outputs get: startIdx
+					sub <- _dict get: outVal withDefault: #{
+						length <- { 0 }
+					}
+					res <- #[]
+					if: (sub length) > 0 {
+						res <- sub findMatches: outputs at: (startIdx + 1)
+						cps <- sub constantProgs
+						if: (cps length) > 0 {
+							isConstant <- true
+							cur <- 0
+							while: { isConstant && cur < (cps length)} do: {
+								isConstant <- outVal = (outputs get: cur)
+								cur <- cur + 1
+							}
+							if: isConstant {
+								foreach: cps :idx tree {
+									res append: cps
+								}
+							}
+						}
+					} else: {
+						if: _hasFirst? {
+							res append: _first
+						}
+					}
+					res
+				}
 			}
 		} else: {
 			_arr <- #[]
@@ -74,6 +104,7 @@
 					_arr append: tree
 				}
 				length <- { _arr length }
+				constantProgs <- { #[] }
 				printwithIndent <- :indent {
 					print: indent . "No more values for these:\n"
 					indent <- indent . "    "
@@ -84,6 +115,9 @@
 				print <- {
 					printwithIndent: ""
 				}
+				findMatches:at <- :outputs :startIdx {
+					_arr
+				}
 			}
 		}
 	}
@@ -103,6 +137,47 @@
 			root
 		}
 
+		solve:withAuth:andInfo:andProg <- :progId :authKey :info :prog {
+			resp <- (requests evalId: progId (info allInputs)) sendWithKey: authKey
+			if: (resp status) = "ok" {
+				matches <- info findMatches: (resp outputs) at: 0
+				noSuccess <- true
+				cur <- 0
+				if: (matches length) = 0 {
+					print: "No matches? :(\n"
+					print: info
+				}
+				while: { noSuccess && cur < (matches length) } do: {
+					prog root!: (matches get: cur)
+					gresp <- (requests guess: progId (string: prog)) sendWithKey: authKey
+					if: (gresp status) = "win" {
+						noSuccess <- false
+					} else: {
+						if: (gresp status) = "mismatch" {
+							failInput <- (gresp values) get: 0
+							failOutput <- (gresp values) get: 1
+							filtered <- #[]
+							foreach: matches :idx tree {
+								prog root!: tree
+								if: (prog run: failInput) = failOutput {
+									filtered append: tree
+								}
+							}
+							matches <- filtered
+							if: (matches length) = 0 {
+								print: "None of our programs actually matched 0x" . (hex: failOutput) ." with input 0x" . (hex: failInput) ." :(\n"
+							}
+						} else: {
+							print: "Got message: " . (gresp message) . ", moving on\n"
+							cur <- cur + 1
+						}
+					}
+				}
+			} else: {
+				print: resp
+			}
+		}
+
 		main <- :args {
 			size <- 3
 			if: (args length) > 1 {
@@ -123,8 +198,16 @@
 					trees <- prog filterTrees: trees ops
 				}
 				info <- classify: prog trees numTests
-				print: info
+				if: (args length) > 5 {
+					progId <- (args get: 4)
+					authKey <- (args get: 5)
+
+					solve: progId withAuth: authKey andInfo: info andProg: prog
+				} else: {
+					print: info
+				}
 			}
+			0
 		}
 	}
 }