{
"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Monotone substrings\n",
+ "\n",
+ "Given a list of numbers, find the length of longest increasing or decreasing substring in the list.\n",
+ "\n",
+ "For instance, the sequence\n",
+ " 10, 1, 2, 3, 4, 5, 5, 5, 6, 4, 3, 5, 6\n",
+ "contains these increasing or decreasing substrings:\n",
+ "* 10, 1\n",
+ "* 1, 2, 3, 4, 5\n",
+ "* 5, 6\n",
+ "* 6, 4, 3\n",
+ "* 3, 5, 6\n",
+ "\n",
+ "As an extension, allow the substring to contain runs of identical numbers, each of which is included in the length of the longest substring.\n",
+ "\n",
+ "If identical numbers are allowed, the above sequence contains substrings:\n",
+ "* 10, 1\n",
+ "* 1, 2, 3, 4, 5, 5, 5, 6\n",
+ "* 6, 4, 3\n",
+ "* 3, 5, 6\n",
+ "\n",
+ "The list is given as a single line of comma-separated integers. "
+ ]
+ },
{
"cell_type": "code",
"execution_count": 1,
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 8,
"metadata": {
"collapsed": false
},
"5"
]
},
- "execution_count": 4,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 9,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ " 2 False\t10\t>\t1\n",
+ " 2 True\t1\t<\t2\n",
+ " 3 True\t2\t<\t3\n",
+ " 4 True\t3\t<\t4\n",
+ " 5 True\t4\t<\t5\n",
+ " 1 True\t5\t=\t5\n",
+ " 1 True\t5\t=\t5\n",
+ " 2 True\t5\t<\t6\n",
+ " 2 False\t6\t>\t4\n",
+ " 3 False\t4\t>\t3\n",
+ " 2 True\t3\t<\t5\n",
+ " 3 True\t5\t<\t6\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "5"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "longest_monotone([10,1,2,3,4,5,5,5,6,4,3,5,6], debug=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
"metadata": {
"collapsed": false
},
" 5 True\t4\t<\t5\n",
" 6 True\t5\t=\t5\n",
" 7 True\t5\t=\t5\n",
- " 4 False\t5\t>\t4\n",
- " 5 False\t4\t>\t3\n",
+ " 8 True\t5\t<\t6\n",
+ " 2 False\t6\t>\t4\n",
+ " 3 False\t4\t>\t3\n",
" 2 True\t3\t<\t5\n",
" 3 True\t5\t<\t6\n"
]
{
"data": {
"text/plain": [
- "7"
+ "8"
]
},
- "execution_count": 5,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "longest_monotone([10,1,2,3,4,5,5,5,4,3,5,6], allow_same=True, debug=True)"
+ "longest_monotone([10,1,2,3,4,5,5,5,6,4,3,5,6], allow_same=True, debug=True)"
]
},
{
{
"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Monotone substrings\n",
+ "\n",
+ "Given a list of numbers, find the length of longest increasing or decreasing substring in the list.\n",
+ "\n",
+ "For instance, the sequence\n",
+ " 10, 1, 2, 3, 4, 5, 5, 5, 6, 4, 3, 5, 6\n",
+ "contains these increasing or decreasing substrings:\n",
+ "* 10, 1\n",
+ "* 1, 2, 3, 4, 5\n",
+ "* 5, 6\n",
+ "* 6, 4, 3\n",
+ "* 3, 5, 6\n",
+ "\n",
+ "As an extension, allow the substring to contain runs of identical numbers, each of which is included in the length of the longest substring.\n",
+ "\n",
+ "If identical numbers are allowed, the above sequence contains substrings:\n",
+ "* 10, 1\n",
+ "* 1, 2, 3, 4, 5, 5, 5, 6\n",
+ "* 6, 4, 3\n",
+ "* 3, 5, 6\n",
+ "\n",
+ "The list is given as a single line of comma-separated integers. "
+ ]
+ },
{
"cell_type": "code",
"execution_count": 1,
{
"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Wordsearch\n",
+ "Given a text file, consisting of three parts (a grid size, a grid, and a list of words), find:\n",
+ "* the words present in the grid, \n",
+ "* the longest word present in the grid, \n",
+ "* the number of words not present in the grid, \n",
+ "* the longest word not present that can be formed from the leftover letters\n",
+ "\n",
+ "The only words that need be considered are the ones given in the list in the puzzle input.\n",
+ "\n",
+ "The puzzle consists of:\n",
+ "1. A line consisting of _w_`x`_h_, where _w_ and _h_ are integers giving the width and height of the grid.\n",
+ "2. The grid itself, consisting of _h_ lines each of _w_ letters.\n",
+ "3. A list of words, one word per line, of arbitrary length. "
+ ]
+ },
{
"cell_type": "code",
"execution_count": 13,
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.5.2+"
+ "version": "3.5.2"
}
},
"nbformat": 4,