Archived
1
0

Updating challenge 02 JN with completed code snippets for submittal.

This commit is contained in:
Shaun Setlock
2020-09-01 18:56:01 -04:00
parent fc95662a3d
commit fc81b5f7fb

View File

@@ -178,41 +178,83 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def find_cycle_length():\n", "def find_cycle_length(s):\n",
" '''\n", " '''\n",
" Function which runs Commander Bunny's randomization algorithm until\n", " Function which runs Commander Bunny's randomization algorithm until\n",
" a cycle is detected. The returned value will represent the number of \n", " a cycle is detected. The returned value will represent the number of \n",
" minions which are caught inside the reassignment cycle. \n", " minions which are caught inside the reassignment cycle. \n",
" '''\n", " '''\n",
" pass" " i = (s+s).find(s, 1, -1)\n",
" print(i)\n",
" return None if i == -1 else s[:i]"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"z = 02222 ... in base 3 ... with padding ... \n", "z = 220101 ... in base 3 ... with padding ... \n",
"z = 12221 ... in base 3 ... with padding ... \n", "z = 212201 ... in base 3 ... with padding ... \n",
"z = 10212 ... in base 3 ... with padding ... \n", "z = 210111 ... in base 3 ... with padding ... \n",
"z = 20211 ... in base 3 ... with padding ... \n", "z = 122221 ... in base 3 ... with padding ... \n",
"z = 20211 ... in base 3 ... with padding ... \n", "z = 102212 ... in base 3 ... with padding ... \n",
"z = 20211 ... in base 3 ... with padding ... \n", "z = 210111 ... in base 3 ... with padding ... \n",
"z = 20211 ... in base 3 ... with padding ... \n", "['220101', '212201', '210111', '122221', '102212']\n",
"z = 20211 ... in base 3 ... with padding ... \n", "5\n",
"z = 20211 ... in base 3 ... with padding ... \n", "2\n",
"z = 20211 ... in base 3 ... with padding ... \n" "102212\n"
] ]
} }
], ],
"source": [ "source": [
"not_match = True\n",
"sequence_list = []\n",
"x = 210022\n",
"i = 0\n",
"while i<10 and not_match:\n",
" x = new_minion_assignment(x, 3)\n",
" if x in sequence_list:\n",
" pass\n",
" not_match = False\n",
" else:\n",
" sequence_list.append(x)\n",
" i += 1\n",
"print(sequence_list)\n",
"print(i-1)\n",
"print(sequence_list.index(x))\n",
"print(sequence_list[i-2])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sequence = \"\"\n",
"sequence_list = []\n",
"x = 32333\n", "x = 32333\n",
"for i in range(10):\n", "for i in range(10):\n",
" x = new_minion_assignment(x, 3)" " x = new_minion_assignment(x, 3)\n",
" sequence += x\n",
" sequence_list.append(x)\n",
" print(sequence)\n",
" print(sequence_list)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"find_cycle_length('12341234')"
] ]
}, },
{ {