{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Survival Driven Development\n", "===========================\n", "\n", "Survival Driven Development (SDD) is the newest software development fad. In this development framework, you specify what the software is supposed to do, then randomly generate source code to fulfill these requirements. Most of these attempts will fail, but hopefully one will succeed.\n", "\n", "Your task is to use SDD to make a function to approximate `x**2 + x`.\n", "\n", "Hint 1: Randomly generate lambda functions using a restricted vocabulary of source fragments.
\n", "`vocab = ['x', 'x', ' ', '+', '-', '*', '/', '1', '2', '3']`\n", "\n", "Hint 2: Only evaluate `x` at a small-ish number of values and save the difference between those answers and the true value of `x**2 + x`.\n", "\n", "Hint 3: SDD is error prone. Be sure to catch your errors!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy\n", "import random" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "vocab = ['x', 'x', ' ', '+', '-', '*', '/', '1', '2', '3']\n", "n_chars = 10 # how many characters to try\n", "n_tries = 100000 # how many trials before we give up\n", "\n", "x = numpy.arange(-3, 3, 0.4)\n", "known_y = x**2 + x" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "for ...:\n", " " ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }