mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
168 lines
4.1 KiB
Plaintext
168 lines
4.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<small><i>This notebook was prepared by [Author](https://github.com/). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).</i></small>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Challenge Notebook"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Problem: Implement a function that groups identical items based on their order in the list.\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",
|
|
"* Can we use extra data structures?\n",
|
|
" * Yes"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Test Cases\n",
|
|
"\n",
|
|
"* group_ordered([1,2,1,3,2]) -> [1,1,2,2,3]\n",
|
|
"* group_ordered(['a','b','a') -> ['a','a','b']\n",
|
|
"* group_ordered([1,1,2,3,4,5,2,1]-> [1,1,1,2,2,3,4,5]\n",
|
|
"* group_ordered([]) -> []\n",
|
|
"* group_ordered([1]) -> [1]\n",
|
|
"* group_ordered(None) -> None"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Algorithm\n",
|
|
"\n",
|
|
"Refer to the [solution notebook](https://github.com/donnemartin/interactive-coding-challenges/templates/foo_solution.ipynb). 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": 1,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"def group_ordered(list_in):\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": 6,
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Success: test_foo\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# %load test_group_ordered.py\n",
|
|
"from nose.tools import assert_equal\n",
|
|
"\n",
|
|
"class TestGroupOrdered(object):\n",
|
|
"\n",
|
|
" def test_group_ordered(self):\n",
|
|
" assert_equal(group_ordered(None), None)\n",
|
|
" assert_equal(group_ordered([]), [])\n",
|
|
" assert_equal(group_ordered([1]), [1])\n",
|
|
" assert_equal(group_ordered([1,2,1,3,2]),[1,1,2,2,3])\n",
|
|
" assert_equal(group_ordered(['a','b','a']),['a','a','b'])\n",
|
|
" assert_equal(group_ordered([1,1,2,3,4,5,2,1]),[1,1,1,2,2,3,4,5])\n",
|
|
" assert_equal(group_ordered([1,2,3,4,3,4]),[1,2,3,3,4,4])\n",
|
|
"\n",
|
|
"def main():\n",
|
|
" test = TestGroupOrdered()\n",
|
|
" test.test_group_ordered()\n",
|
|
"\n",
|
|
"if __name__ == '__main__':\n",
|
|
" main()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Solution Notebook\n",
|
|
"\n",
|
|
"Review the [solution notebook](https://github.com/donnemartin/interactive-coding-challenges/templates/foo_solution.ipynb) for a discussion on algorithms and code solutions."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 2",
|
|
"language": "python",
|
|
"name": "python2"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|