%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Combinatorics
% Math 480 Spring 2015
%

\documentclass[10pt]{article}
\usepackage[textheight=10in]{geometry}

\usepackage{verbatim}
\usepackage{amsmath}
\usepackage{amsfonts} % to get \mathbb letters

\usepackage[utf8]{inputenc}
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{9} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{9}  % for normal
% Defining colors
\usepackage{color}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}

\usepackage{listings}

%Python style from 
%http://tex.stackexchange.com/questions/199375/problem-with-listings-package-for-python-syntax-coloring
\newcommand\pythonstyle{\lstset{
  language=Python,
  backgroundcolor=\color{white}, %%%%%%%
  basicstyle=\ttm,
  keywordstyle=\ttb\color{deepblue},
  emph={MyClass,__init__},          
  emphstyle=\ttb\color{deepred},    
  stringstyle=\color{deepgreen},
  commentstyle=\color{red},  %%%%%%%%
  frame=tb,                       
  showstringspaces=false,
  numbers=left,numberstyle=\tiny,numbersep =5pt
}}

\usepackage{hyperref}

\begin{document}

\pythonstyle{}

%%%%%%%%%%%%%%%% start here %%%%%%%%%%%%%%%%
\begin{center}
\Large{
Discrete Mathematics in Python \\
Ethan Bolker \\
\today
}
\end{center}

\section{Permutations}

Here's a function that write out all the permutations of a list.

\lstinputlisting{combinatorics1.py}

with its outputn

\begin{verbatim}
python combinatorics1.py 
permute([1,2,3])
[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]
print(permute([]))
[]
permute(["a"]))
[['a']]
permute([1,2,2])
[[1, 2, 2], [2, 1, 2], [2, 2, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1]]
\end{verbatim}

Lessons here:
\begin{itemize}
\item Turning recursive pseudocode into a recursive program
\item Slicing a list returns a copy
\item Single and double quotes
\item This algorithm isn't smart about repetitions
\item Should find the built in function in \lstinline!itertools!
\item Should use \lstinline!yield! instead of \lstinline!return!
\end{itemize}
\newpage
\emph{
Here is the \LaTeX{} source for this document. You can cut it from the
pdf and use it to start your answers. I used the} \verb!\jobname! 
\emph{macro for the source file name, so you can call your file by any
  name you like.}
\verbatiminput{\jobname}

\end{document}

