"cells": [
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 3,
"metadata": {
"collapsed": true
},
},
{
"cell_type": "code",
- "execution_count": 39,
+ "execution_count": 4,
"metadata": {
"collapsed": false
},
" 'Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1']"
]
},
- "execution_count": 39,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 40,
+ "execution_count": 5,
"metadata": {
"collapsed": false
},
" 'texture': 2}}"
]
},
- "execution_count": 40,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 31,
+ "execution_count": 6,
"metadata": {
"collapsed": false
},
" range(capacity+1), range(capacity+1))))"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "def recipe(t, capacity):\n",
+ " return [('Frosting', t[0]), ('Butterscotch', t[1]), ('Candy', t[2]), ('Sugar', capacity-sum(t))]"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 32,
" range(capacity+1))))"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "collapsed": false,
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "18965440"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "capacity = 100\n",
+ "max(score(recipe(t, capacity), ingredients) \n",
+ " for t in filter(lambda t: sum(t) <= capacity,\n",
+ " itertools.product(range(capacity+1), range(capacity+1), \n",
+ " range(capacity+1))))"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 38,
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 10,
"metadata": {
"collapsed": false
},
},
{
"cell_type": "code",
- "execution_count": 42,
+ "execution_count": 11,
"metadata": {
"collapsed": false,
"scrolled": true
"15862900"
]
},
- "execution_count": 42,
+ "execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"capacity = 100\n",
- "max(score([('Frosting', f), ('Butterscotch', b), ('Candy', c), ('Sugar', capacity-(f+b+c))], ingredients) \n",
- " for f, b, c in filter(lambda t: calories([('Frosting', t[0]), ('Butterscotch', t[1]), \n",
- " ('Candy', t[2]), ('Sugar', capacity-sum(t))], ingredients) == 500,\n",
+ "max(score(recipe(t, capacity), ingredients) \n",
+ " for t in filter(lambda t: calories(recipe(t, capacity), ingredients) == 500,\n",
" filter(lambda t: sum(t) <= capacity,\n",
" itertools.product(range(capacity+1), range(capacity+1), \n",
" range(capacity+1)))))"