{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Challenge Notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Problem: Given an array of 32 integers, find an int not in the input.  Use a minimal amount of memory.\n",
    "\n",
    "* [Constraints](#Constraints)\n",
    "* [Test Cases](#Test-Cases)\n",
    "* [Algorithm](#Algorithm)\n",
    "* [Code](#Code)\n",
    "* [Unit Test](#Unit-Test)\n",
    "* [Solution Notebook](#Solution-Notebook)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Constraints\n",
    "\n",
    "* Are we working with non-negative ints?\n",
    "    * Yes\n",
    "* What is the range of the integers?\n",
    "    * Discuss the approach for 4 billion integers\n",
    "    * Implement for 32 integers\n",
    "* Can we assume the inputs are valid?\n",
    "    * No"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Cases\n",
    "\n",
    "* None -> Exception\n",
    "* [] -> Exception\n",
    "* General case\n",
    "    * There is an int excluded from the input -> int\n",
    "    * There isn't an int excluded from the input -> None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Algorithm\n",
    "\n",
    "Refer to the [Solution Notebook]().  If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from bitstring import BitArray  # run pip install bitstring\n",
    "\n",
    "\n",
    "class Bits(object):\n",
    "\n",
    "    def new_int(self, array, max_size):\n",
    "        # TODO: Implement me\n",
    "        pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Unit Test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**The following unit test is expected to fail until you solve the challenge.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# %load test_new_int.py\n",
    "from nose.tools import assert_equal, assert_raises\n",
    "\n",
    "\n",
    "class TestBits(object):\n",
    "\n",
    "    def test_new_int(self):\n",
    "        bits = Bits()\n",
    "        max_size = 32\n",
    "        assert_raises(TypeError, bits.new_int, None, max_size)\n",
    "        assert_raises(TypeError, bits.new_int, [], max_size)\n",
    "        data = [item for item in range(30)]\n",
    "        data.append(31)\n",
    "        assert_equal(bits.new_int(data, max_size), 30)\n",
    "        data = [item for item in range(32)]\n",
    "        assert_equal(bits.new_int(data, max_size), None)\n",
    "        print('Success: test_find_int_excluded_from_input')\n",
    "\n",
    "\n",
    "def main():\n",
    "    test = TestBits()\n",
    "    test.test_new_int()\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Solution Notebook\n",
    "\n",
    "Review the [Solution Notebook]() for a discussion on algorithms and code solutions."
   ]
  }
 ],
 "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
