# HG changeset patch # User William Morgan # Date 1376212663 25200 # Node ID a8db0f4039aa8e7916d19a33bb6bd90f47a3e2cb # Parent 4750da71cae6956a53f6c6cdc3b971627ec52811# Parent 1cadb591eef1c4504ee904eb21c60e411e0cf43a merge diff -r 4750da71cae6 -r a8db0f4039aa data/train/IxVBHQTlzePZHljYiBdZLwKh.json --- /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 diff -r 4750da71cae6 -r a8db0f4039aa src/solver.tp --- 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 } } }