Working assignment.

Wrote both functions including proof.