{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "n = 100\n", "choices = range(n)\n", "k = 2 # The code won't explicitly reference k, but this is what it will be in the examples below" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10000\n" ] } ], "source": [ "# Permutations with replacement\n", "\n", "permutations = []\n", "\n", "for i in choices:\n", " for j in choices:\n", " permutation = [i, j]\n", " permutations.append(permutation)\n", "\n", "print(len(permutations))\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "9900\n" ] } ], "source": [ "# Permutations without replacement\n", "\n", "permutations = []\n", "\n", "for i in choices:\n", " for j in choices:\n", " if i != j:\n", " permutation = [i, j]\n", " permutations.append(permutation)\n", "\n", "print(len(permutations))\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4950\n" ] } ], "source": [ "# Combinations\n", "\n", "combinations = []\n", "\n", "for i in choices:\n", " for j in choices:\n", " if i != j:\n", " combination = set([i, j])\n", " if combination not in combinations:\n", " combinations.append(combination)\n", "\n", "print(len(combinations))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 2 }