\documentclass[a4paper,12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{graphicx} %BIlder einbinden
\usepackage{amsmath} %erweiterte Mathe-Zeichen
\usepackage{amsfonts} %weitere fonts
\usepackage[utf8]{inputenc} %Umlaute & Co
\usepackage{hyperref} %Links
\usepackage{ifthen} %ifthenelse
\usepackage{enumerate}

\usepackage{color}
\usepackage{algpseudocode} %Pseudocode
\usepackage{dsfont} % schöne Zahlenräumezeichen
\usepackage{amssymb, amsthm} %noch stärker erweiterte Mathe-Zeichen
\usepackage{tikz} %TikZ ist kein Zeichenprogramm
\usetikzlibrary{trees,automata,arrows,shapes}

\pagestyle{empty}


\topmargin-50pt

\newcounter{aufgabe}
\def\tand{&}

\newcommand{\makeTableLine}[2][0]{%
  \setcounter{aufgabe}{1}%
  \whiledo{\value{aufgabe} < #1}%
  {%
    #2\tand\stepcounter{aufgabe}%
  }
}

\newcommand{\aufgTable}[1]{
  \def\spalten{\numexpr #1 + 1 \relax}
  \begin{tabular}{|*{\spalten}{p{1cm}|}}
    \makeTableLine[\spalten]{A\theaufgabe}$\Sigma$~~\\ \hline
    \rule{0pt}{15pt}\makeTableLine[\spalten]{}\\
  \end{tabular}
}

\def\header#1#2#3#4#5#6#7{\pagestyle{empty}
\begin{minipage}[t]{0.47\textwidth}
\begin{flushleft}
{\bf #4}\\
#5
\end{flushleft}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{flushright}
#6 \vspace{0.5cm}\\
%                 Number of Columns    Definition of Columns      second empty line
% \begin{tabular}{|*{5}{C{1cm}|}}\hline A1&A2&A3&A4&$\Sigma$\\\hline&&&&\\\hline\end{tabular}\\\vspace*{0.1cm}
\aufgTable{#7}
\end{flushright}
\end{minipage}
\vspace{1cm}
\begin{center}
{\Large\bf Sheet #1}

{(Hand in #3)}
\end{center}
}



%counts the exercisenumber
\newcounter{n}

%Kommando für Aufgaben
%\Aufgabe{AufgTitel}{Punktezahl}
\newcommand{\Aufgabe}[2]{\stepcounter{n}
    \textbf{Exercise \arabic{n}: #1} (#2 Points)\\}

\newcommand{\textcorr}[1]{\textcolor{red}{#1}}
\newenvironment{corr}{\color{red}}{\color{black}\newline}
\newcommand{\ok}{\begin{corr}
            $\checkmark$
        \end{corr}}

\begin{document}
    %\header{BlattNr}{Tutor}{Abgabedatum}{Vorlesungsname}{Namen}{Semester}{Anzahl Aufgaben}
    \header{1}{}{2015-04-22}{Intelligent Systems I}{\textit{Maximus Mutschler}\\ \textit{Jan-Peter Hohloch}
    }{SS 15}{4}
    \vspace{1cm}
    \Aufgabe{Python}{4}
        done\\\ok
    \Aufgabe{Poker}{2+2+4=8}
        \begin{enumerate}[1.]
            \item possible hands: ${52 \choose 5}=2598960$\\
                hands with exaclty one pair: ${13\choose 1}\cdot{4\choose 2}\cdot {12\choose 3}\cdot 4^3=1098240$\\
                $\mathds{P}(1\ pair)=\frac{1098240}{2598960}=\frac{352}{833}\approx 0.423$\ok
            \item hands with exaclty two pairs: ${13\choose 2}{4\choose 2}^2\cdot 11\cdot 4=123552$\\
            $\mathds{P}(2\ pairs)=\frac{123552}{2598960}=\frac{198}{4165}\approx 0.0475$\ok
            \item \begin{enumerate}[(a)]
                \item possible hands without Spades: ${39\choose 5}=575757$\\
                hands with exaclty two pairs without Spades: ${13\choose 2}{3\choose 2}^2\cdot 11\cdot 3=23166$\\
                $\mathds{P}(2\ pairs|\neg Spades)=\frac{23166}{575757}=\frac{198}{4921}\approx 0.0402$\ok\\
                one pair:\\
                ${13\choose 1}{3\choose 2}{12 \choose 3}\cdot 3^3=231660$\\
                $\mathds{P}(1\ pair|\neg Spades)=\frac{231660}{575757}=\frac{1980}{4921}\approx 0.402$\ok
                \item \begin{enumerate}[(i)]
                    \item $A:=1\ pair,\ B:=\neg Spades$\\
                        $P(A|B)=\frac{P(B|A)P(A)}{P(B)}$\\
                        $P(A)=\frac{352}{833},\ P(B)=\frac{39}{52}\cdot\frac{38}{51}\cdot\frac{37}{50}\cdot\frac{36}{49}\cdot\frac{35}{48}=\frac{2109}{9520}$\\
                        $P(B|A)=1-P(\neg B| A)=1-\left(\frac{1}{4}+\frac{3}{4}\cdot\frac{1}{4}+\left(\frac{3}{4}\right)^2\frac{1}{4}+\left(\frac{3}{4}\right)^3\frac{1}{4}+\left(\frac{3}{4}\right)^4\frac{1}{3}\right)=1-\frac{101}{128}=\frac{27}{128}\approx 0.211$\\\begin{corr}
                            easier approach: $P(B|A)=\frac{\#\{1\ pair,\ no Spades\}}{\#\{1\ pair\}}$
                        \end{corr}
                        $P(A|B)=\frac{\frac{27}{128}\cdot \frac{352}{833}}{\frac{2109}{9520}}=\frac{1980}{4921}\approx 0.402$\ok
                    \item $A:=2\ pairs,\ P(A)=\frac{198}{4165}$, B as above\\
                        $P(B|A)=1-\left(\frac{1}{4}+\frac{3}{4}\cdot\frac{1}{4}+\left(\frac{3}{4}\right)^2\cdot\frac{1}{4}+\left(\frac{3}{4}\right)^3\cdot\frac{1}{3}+\left(\frac{3}{4}\right)^3\frac{2}{3}\cdot\frac{1}{3}\right)=\frac{3}{16}$\\
                        $P(A|B)=\frac{\frac{3}{16}\cdot \frac{198}{4165}}{\frac{2109}{9520}}=\frac{198}{4921}\approx0.0402$\ok
                \end{enumerate}
            \end{enumerate}
        \end{enumerate}
    \Aufgabe{Random Variables}{2+2+2=6}
        \begin{enumerate}
            \item $F\left(\frac{3}{2}\right)-F\left(\frac{1}{2}\right)=\frac{3}{4}-\frac{1}{4}=\frac{1}{2}$\ok
            \item
             $x^2<x\Leftrightarrow x\in (0,1)$ \\
             $\Rightarrow \mathds{P}(Y<X)=\mathds{P}(0< X<1)=F\left(1\right)-F\left(0\right)=\frac{1}{2}-0=\frac{1}{2}$\ok\\
             \begin{corr}
                other approach (first lower than 0 and higher than 4 ($\rightarrow$ 0, 1), then compute density):\\
                $f_Y(y)=\begin{cases}
                    0 & y<0\\
                    \frac{1}{2}\frac{1}{2\sqrt{y}} & 0\le y\le 4\\
                    0 & y>4
                \end{cases}\\
                F_Y(y)=\begin{cases}
                    0 & y<0\\
                    \frac{1}{2}\sqrt{y} & 0\le y\le 4\\
                    1 & y>4
                \end{cases}$
             \end{corr}
            \item $
            F_z(z) = F_x(g^{-1}(z))\\
            g(X)=\sqrt{X} \\ g^{-1}(z)= z^2\\
            F_z(z)= \frac{1}{2} z^2\textcorr{\text{, where }0<z<\sqrt{2}}\\
            F_Z(z)=\begin{cases}
                0 & if\ z<0\\
                \frac{1}{2} z^2 & if\ 0\leq z\leq \sqrt2\\
                1 & if\ z>\sqrt2
            \end{cases}$\ok
           \\ reference: http://math.arizona.edu/$\sim$jwatkins/f-transform.pdf
        \end{enumerate}\pagebreak
    \Aufgabe{Keep Rolling!}{4}
        \begin{align*}
            \mathds{E}(X)
            &=\sum\limits_{i=1}^{\infty} i\cdot p\cdot \left(1-p\right)^{i-1}\\
            &=p\cdot\sum\limits_{i=1}^{\infty} i\left(1-p\right)^{i-1}\\
            &=p\cdot \frac{d}{dp}\left[ -\sum\limits_{i=0}^{\infty}\left(1-p\right)^i\right] &\text{(geometric series)}\\
            &=p\cdot \frac{d}{dp}\left(-\frac{1}{p}\right)\\
            &=p\cdot \frac{1}{p^2}\\
            &=\frac{1}{p}
        \end{align*}
        $\Rightarrow\mathds{E}(X)=\frac{1}{p}=\frac{1}{\frac{1}{6}}=6$\ok
        \begin{corr}
            other approach:\\
            $X=\#$ needed to throw dice\\
            $T=$ if we have 6$\rightarrow\begin{cases}
                0\\1
            \end{cases}\\
            \mathds{E}(X|T=1)=1\\
            \mathds{E}(X|T=0)=\sum\limits_{k=1}^\infty p(x=k|T=0)=\mathds{E}(X+1)\\
            \mathds{E}(X)=\frac{1}{6}+\frac{5}{6}\left(\mathds{E}(X+1)\right)=\frac{1}{6}+\frac{5}{6}\mathds{E}(X)+\frac{5}{6}$
        \end{corr}
\end{document}

