3 ms·
Additionally: in the spirit of good natured fun, here's my (clearly non-serious) entry: '' def findPossibleSolutions(querytext): for result in GoogleCodeSear
by frig 17y ago
Additionally: in the spirit of good natured fun, here's my (clearly non-serious) entry:
''
def findPossibleSolutions(querytext):
for result in GoogleCodeSearch(query=querytext):
yield result
def tryOutPossibleSolution(candidate):
output = None
with SafeSandboxedEvaluatorFactoryFactory(candidate.language).safeSandboxedEvaluator() as evaluator:
output = evaluator.evaluate(candidate.code)
return output
def validatePossibleSolution(candidate, validator):
return validator(tryOutPossibleSolution(candidate))
def giveMeValidSolutionSourceCodes(querytext,validator):
for validSolution in (candidate for candidate in findPossibleSolutions(querytext) if validatePossibleSolution(candidate,validator)):
yield {'source'=validSolution.code,'extension'=validSolution.languageExtension}
if __name__ == "__main__":
helloWorlds = giveMeValidSolutionSourceCodes("hello world", lambda x: x == "hello world")
firstValidSource = helloWorlds()
if firstValidSource:
print "helloworld.%s:\n\n%s" % (firstValidSource["extension"],firstValidSource["source"])
else:
print "helloworld.py:\n\nprint \"hello world\"" # default case
''
Edit: if there's a way to reproduce source code please inform.
- DougBTX 17y agoIndent by 2+ spaces, like so: pre
- frig 17y agoThanks.
- frig 17y agoMissed the edit interval, so: def findPossibleSolutions(querytext): for result in GoogleCodeSearch(query=querytext): yield result def tryOutPossibleSolution(candidate): output = None with SafeSandboxedEvaluatorFactoryFactory(candidate.language).safeSandboxedEvaluator() as evaluator: output = evaluator.evaluate(candidate.code) return output def validatePossibleSolution(candidate, validator): return validator(tryOutPossibleSolution(candidate)) def giveMeValidSolutionSourceCodes(querytext,validator): for validSolution in (candidate for candidate in findPossibleSolutions(querytext) if validatePossibleSolution(candidate,validator)): yield {'source'=validSolution.code,'extension'=validSolution.languageExtension} if __name__ == "__main__": helloWorlds = giveMeValidSolutionSourceCodes("hello world", lambda x: x == "hello world") firstValidSource = helloWorlds() if firstValidSource: print "helloworld.%s:\n\n%s" % (firstValidSource["extension"],firstValidSource["source"]) else: print "helloworld.py:\n\nprint \"hello world\"" # default case ''