Added unique chars challenge.

This commit is contained in:
Donne Martin
2015-07-03 19:57:24 -04:00
parent 73ec41e427
commit 8ac0bd3f69
3 changed files with 260 additions and 21 deletions

View File

@@ -4,7 +4,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<small><i>This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://bit.ly/code-notes).</i></small>"
"<small><i>This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/coding-challenges).</i></small>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
@@ -30,11 +37,13 @@
"source": [
"## Constraints\n",
"\n",
"*Problem statements are often intentionally ambiguous. Identifying constraints and stating assumptions can help to ensure you code the intended solution.*\n",
"*Problem statements are sometimes ambiguous. Identifying constraints and stating assumptions can help to ensure you code the intended solution.*\n",
"\n",
"* Can I assume the string is ASCII?\n",
"* Can you assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Can we assume this is case sensitive?\n",
" * Yes\n",
"* Can you use additional data structures? \n",
" * Yes"
]
@@ -185,15 +194,51 @@
]
},
{
"cell_type": "markdown",
"metadata": {},
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_unique_chars.py\n"
]
}
],
"source": [
"*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand. You generally will not be asked to write a unit test like what is shown below.*"
"%%writefile test_unique_chars.py\n",
"from nose.tools import assert_equal\n",
"\n",
"\n",
"class TestUniqueChars(object):\n",
"\n",
" def test_unique_chars(self, func):\n",
" assert_equal(func(''), True)\n",
" assert_equal(func('foo'), False)\n",
" assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n",
"\n",
"def main():\n",
" test = TestUniqueChars()\n",
" test.test_unique_chars(unique_chars)\n",
" try:\n",
" test.test_unique_chars(unique_chars_hash)\n",
" test.test_unique_chars(unique_chars_inplace)\n",
" except NameError:\n",
" # Alternate solutions are only defined\n",
" # in the solutions file\n",
" pass\n",
" \n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"collapsed": false
},
@@ -209,20 +254,7 @@
}
],
"source": [
"from nose.tools import assert_equal\n",
"\n",
"class Test(object):\n",
" def test_unique_chars(self, func):\n",
" assert_equal(func(''), True)\n",
" assert_equal(func('foo'), False)\n",
" assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n",
"\n",
"if __name__ == '__main__':\n",
" test = Test()\n",
" test.test_unique_chars(unique_chars)\n",
" test.test_unique_chars(unique_chars_hash)\n",
" test.test_unique_chars(unique_chars_inplace)"
"%run -i test_unique_chars.py"
]
}
],