{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solutions for Counting Level 2, version 6\n", "\n", "## Problem 1(a)\n", "\n", "We are going to count the number of six-letter strings that contain exactly one vowel. The strategy is: \n", "\n", "1. First determine the number of ways a single vowel can be inserted into a six-letter string. \n", "2. Then determine the number of ways a single vowel can be inserted, once we've chosen the location. \n", "3. Finally determine the number of ways to fill the remaining five positions with consonants. \n", "\n", "First: The number of ways a single vowel can be inserted into a six letter string is $C(6,1) = 6$ -- i.e. we can put the vowel in one of six positions. \n", "\n", "Second: Once the position is determined, there are five vowels from which to choose, so $C(5,1) = 5$ ways to insert a vowel with a determined position. \n", "\n", "Third: The remaining five positions are a free choice of 21 letters, so there are $21^5$ ways to do this. \n", "\n", "In all, then, the total number of strings being described is $6 \\times 5 \\times 21^5$: " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "122523030" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "6*5*21^5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 1(b) \n", "\n", "We are now going to count the number of six-letter strings that have exactly _two_ vowels. We will use the same strategy as before: \n", "\n", "1. First determine the number of ways two vowels can be inserted into a six-letter string. \n", "2. Then determine the number of ways two vowels can be inserted, once we've chosen the locations. \n", "3. Finally determine the number of ways to fill the remaining four positions with consonants. \n", "\n", "This time the number of positions we can choose is 2 out of 6, or $C(6,2)$ \n", "\n", "The number of ways to fill those two positions is $5^2$, since they are a free choice of two vowels and we can repeat the vowel if we want. \n", "\n", "Finally, as above, the remaining four positions have $21^4$ possible options since it's a free choice of four letters out of 21. \n", "\n", "So the total number of strings this time is $C(6,2) \\times 5^2 \\times 21^4$: " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "72930375" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binomial(6,2) * 5^2 * 21^4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 1(c)\n", "\n", "The number of strings with at least one vowel is the complement of the number of strings with no vowels. There are $26^6$ strings that we can possibly make, and $21^6$ of those have no vowels. Therefore the number of strings we want is $26^6 - 21^6$: " ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "223149655" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "26^6 - 21^6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 1(d)\n", "\n", "The number of strings with at least two vowels is $26^6$ (the total number of strings possible) minus the number of strings with no vowels, minus the number of strings with exactly one vowel. There are $21^6$ strings with no vowels. Above, we determined there were $6 \\times 5 \\times 21^5$ strings with exactly one vowel. So the number of strings we want is $26^6 - 21^6 - 6 \\times 5 \\times 21^5$:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "100626625" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "26^6 - 21^6 - 6*5*21^5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 2\n", "\n", "This is simply the number of ways to choose 5 objects from a set of 52, which is $C(52,5)$: " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "2598960" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binomial(52,5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "_Question: Why isn't it $52 \\times 51 \\times 50 \\times 49 \\times 48$?_ It's because this product counts the number of ways that a selection of 5 objects from a group of 52 can be rearranged. It's as if you had a race with 52 competitors, and you wanted to know the number of ways to award first through fifth place. The same group of people arranged in a different order would be counted differently. But this is not the case with a hand of cards -- the order of the arrangement doesn't matter. For example a hand consisting of 4 of spades, 3 of clubs, 3 of diamonds, 10 of hearts, and ace of spades is the same had as 4 of spades, ace of spades, 3 of diamonds, 10 of hearts, and 3 of clubs. The product listed here would be exactly $5!$ times too large because it takes ordering into account when it shouldn't. \n", "\n", "## Problem 3\n", "\n", "According to the Binomial Theorem, this coefficient would be $C(201, 100)$: " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "180200509365116430834121184084894227116588341829287927773320" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#3\n", "binomial(201,100)" ] } ], "metadata": { "kernelspec": { "display_name": "Sage 6.9", "language": "", "name": "sage-6.9" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" }, "name": "Counting v6 solution.ipynb" }, "nbformat": 4, "nbformat_minor": 0 }