Jump to content

Z15076: Difference between revisions

From Wikifunctions
No edit summary
add memoization
 
Line 11: Line 11:
"Z1K1": "Z16",
"Z1K1": "Z16",
"Z16K1": "Z610",
"Z16K1": "Z610",
"Z16K2": "def Z15075(Z15075K1):\n\tdef P(n):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\telif n == 1 or n == 2:\n\t\t\treturn 0\n\t\telse:\n\t\t\treturn P(n-2)+P(n-3)\n\treturn P(Z15075K1)"
"Z16K2": "def Z15075(Z15075K1):\n\tknownValues = {}\n\tdef P(n):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\telif n == 1 or n == 2:\n\t\t\treturn 0\n\t\telif n in knownValues:\n\t\t\treturn knownValues[n]\n\t\telse:\n\t\t\tresult = P(n-2)+P(n-3)\n\t\t\tknownValues[n] = result\n\t\t\treturn result\n\treturn P(Z15075K1)"
}
}
},
},

Latest revision as of 18:24, 11 April 2024

This page displays in a limited way without JavaScript.