diff --git a/challenge_02/challenge_02.ipynb b/challenge_02/challenge_02.ipynb index 39cada4..3313780 100644 --- a/challenge_02/challenge_02.ipynb +++ b/challenge_02/challenge_02.ipynb @@ -178,41 +178,83 @@ "metadata": {}, "outputs": [], "source": [ - "def find_cycle_length():\n", + "def find_cycle_length(s):\n", " '''\n", " Function which runs Commander Bunny's randomization algorithm until\n", " a cycle is detected. The returned value will represent the number of \n", " minions which are caught inside the reassignment cycle. \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", - "execution_count": 5, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "z = 02222 ... in base 3 ... with padding ... \n", - "z = 12221 ... in base 3 ... with padding ... \n", - "z = 10212 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n", - "z = 20211 ... in base 3 ... with padding ... \n" + "z = 220101 ... in base 3 ... with padding ... \n", + "z = 212201 ... in base 3 ... with padding ... \n", + "z = 210111 ... in base 3 ... with padding ... \n", + "z = 122221 ... in base 3 ... with padding ... \n", + "z = 102212 ... in base 3 ... with padding ... \n", + "z = 210111 ... in base 3 ... with padding ... \n", + "['220101', '212201', '210111', '122221', '102212']\n", + "5\n", + "2\n", + "102212\n" ] } ], "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", "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')" ] }, {