Skip to content

Instantly share code, notes, and snippets.

@aheld
Created February 9, 2014 18:33
Show Gist options
  • Save aheld/8903763 to your computer and use it in GitHub Desktop.
Save aheld/8903763 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"def bray(n):\n",
" if n < 1: return 0\n",
" if n == 1: return 1\n",
" accumulator = 1 + (2 * n-2)\n",
" return accumulator + bray(n-1)\n",
"\n",
"for n in range(100):\n",
" bray(n)\n",
" print(\"n=%3d: bray(n) = %s\\t square(n): %5d\" % (n,bray(n),n*n) )"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"n= 0: bray(n) = 0\t square(n): 0\n",
"n= 1: bray(n) = 1\t square(n): 1\n",
"n= 2: bray(n) = 4\t square(n): 4\n",
"n= 3: bray(n) = 9\t square(n): 9\n",
"n= 4: bray(n) = 16\t square(n): 16\n",
"n= 5: bray(n) = 25\t square(n): 25\n",
"n= 6: bray(n) = 36\t square(n): 36\n",
"n= 7: bray(n) = 49\t square(n): 49\n",
"n= 8: bray(n) = 64\t square(n): 64\n",
"n= 9: bray(n) = 81\t square(n): 81\n",
"n= 10: bray(n) = 100\t square(n): 100\n",
"n= 11: bray(n) = 121\t square(n): 121\n",
"n= 12: bray(n) = 144\t square(n): 144\n",
"n= 13: bray(n) = 169\t square(n): 169\n",
"n= 14: bray(n) = 196\t square(n): 196\n",
"n= 15: bray(n) = 225\t square(n): 225\n",
"n= 16: bray(n) = 256\t square(n): 256\n",
"n= 17: bray(n) = 289\t square(n): 289\n",
"n= 18: bray(n) = 324\t square(n): 324\n",
"n= 19: bray(n) = 361\t square(n): 361\n",
"n= 20: bray(n) = 400\t square(n): 400\n",
"n= 21: bray(n) = 441\t square(n): 441\n",
"n= 22: bray(n) = 484\t square(n): 484\n",
"n= 23: bray(n) = 529\t square(n): 529\n",
"n= 24: bray(n) = 576\t square(n): 576\n",
"n= 25: bray(n) = 625\t square(n): 625\n",
"n= 26: bray(n) = 676\t square(n): 676\n",
"n= 27: bray(n) = 729\t square(n): 729\n",
"n= 28: bray(n) = 784\t square(n): 784\n",
"n= 29: bray(n) = 841\t square(n): 841\n",
"n= 30: bray(n) = 900\t square(n): 900\n",
"n= 31: bray(n) = 961\t square(n): 961\n",
"n= 32: bray(n) = 1024\t square(n): 1024\n",
"n= 33: bray(n) = 1089\t square(n): 1089\n",
"n= 34: bray(n) = 1156\t square(n): 1156\n",
"n= 35: bray(n) = 1225\t square(n): 1225\n",
"n= 36: bray(n) = 1296\t square(n): 1296\n",
"n= 37: bray(n) = 1369\t square(n): 1369\n",
"n= 38: bray(n) = 1444\t square(n): 1444\n",
"n= 39: bray(n) = 1521\t square(n): 1521\n",
"n= 40: bray(n) = 1600\t square(n): 1600\n",
"n= 41: bray(n) = 1681\t square(n): 1681\n",
"n= 42: bray(n) = 1764\t square(n): 1764\n",
"n= 43: bray(n) = 1849\t square(n): 1849\n",
"n= 44: bray(n) = 1936\t square(n): 1936\n",
"n= 45: bray(n) = 2025\t square(n): 2025\n",
"n= 46: bray(n) = 2116\t square(n): 2116\n",
"n= 47: bray(n) = 2209\t square(n): 2209\n",
"n= 48: bray(n) = 2304\t square(n): 2304\n",
"n= 49: bray(n) = 2401\t square(n): 2401\n",
"n= 50: bray(n) = 2500\t square(n): 2500\n",
"n= 51: bray(n) = 2601\t square(n): 2601\n",
"n= 52: bray(n) = 2704\t square(n): 2704\n",
"n= 53: bray(n) = 2809\t square(n): 2809\n",
"n= 54: bray(n) = 2916\t square(n): 2916\n",
"n= 55: bray(n) = 3025\t square(n): 3025\n",
"n= 56: bray(n) = 3136\t square(n): 3136\n",
"n= 57: bray(n) = 3249\t square(n): 3249\n",
"n= 58: bray(n) = 3364\t square(n): 3364\n",
"n= 59: bray(n) = 3481\t square(n): 3481\n",
"n= 60: bray(n) = 3600\t square(n): 3600\n",
"n= 61: bray(n) = 3721\t square(n): 3721\n",
"n= 62: bray(n) = 3844\t square(n): 3844\n",
"n= 63: bray(n) = 3969\t square(n): 3969\n",
"n= 64: bray(n) = 4096\t square(n): 4096\n",
"n= 65: bray(n) = 4225\t square(n): 4225\n",
"n= 66: bray(n) = 4356\t square(n): 4356\n",
"n= 67: bray(n) = 4489\t square(n): 4489\n",
"n= 68: bray(n) = 4624\t square(n): 4624\n",
"n= 69: bray(n) = 4761\t square(n): 4761\n",
"n= 70: bray(n) = 4900\t square(n): 4900\n",
"n= 71: bray(n) = 5041\t square(n): 5041\n",
"n= 72: bray(n) = 5184\t square(n): 5184\n",
"n= 73: bray(n) = 5329\t square(n): 5329\n",
"n= 74: bray(n) = 5476\t square(n): 5476\n",
"n= 75: bray(n) = 5625\t square(n): 5625\n",
"n= 76: bray(n) = 5776\t square(n): 5776\n",
"n= 77: bray(n) = 5929\t square(n): 5929\n",
"n= 78: bray(n) = 6084\t square(n): 6084\n",
"n= 79: bray(n) = 6241\t square(n): 6241\n",
"n= 80: bray(n) = 6400\t square(n): 6400\n",
"n= 81: bray(n) = 6561\t square(n): 6561\n",
"n= 82: bray(n) = 6724\t square(n): 6724\n",
"n= 83: bray(n) = 6889\t square(n): 6889\n",
"n= 84: bray(n) = 7056\t square(n): 7056\n",
"n= 85: bray(n) = 7225\t square(n): 7225\n",
"n= 86: bray(n) = 7396\t square(n): 7396\n",
"n= 87: bray(n) = 7569\t square(n): 7569\n",
"n= 88: bray(n) = 7744\t square(n): 7744\n",
"n= 89: bray(n) = 7921\t square(n): 7921\n",
"n= 90: bray(n) = 8100\t square(n): 8100\n",
"n= 91: bray(n) = 8281\t square(n): 8281\n",
"n= 92: bray(n) = 8464\t square(n): 8464\n",
"n= 93: bray(n) = 8649\t square(n): 8649\n",
"n= 94: bray(n) = 8836\t square(n): 8836\n",
"n= 95: bray(n) = 9025\t square(n): 9025\n",
"n= 96: bray(n) = 9216\t square(n): 9216\n",
"n= 97: bray(n) = 9409\t square(n): 9409\n",
"n= 98: bray(n) = 9604\t square(n): 9604\n",
"n= 99: bray(n) = 9801\t square(n): 9801\n"
]
}
],
"prompt_number": 5
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment