diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index f02523c4..46fd3ba6 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -25,9 +25,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ "import hashlib\n", "\n", @@ -35,7 +43,7 @@ " hash_object = hashlib.sha256(input_string.encode())\n", " hash_int = int(hash_object.hexdigest(), 16)\n", " return (hash_int % 3) + 1\n", - "input_string = \"your_first_name_here\"\n", + "input_string = \"abraham\"\n", "result = hash_to_range(input_string)\n", "print(result)\n" ] @@ -67,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -112,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -142,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -165,11 +173,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nAnswer: \\n\\nIn the list above, there are non-zero elements and zero elements, sort the list in descending order, then move all the zeros elements behind the non-zero elements\\n'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your answer here" + "# Your answer here\n", + "'''\n", + "Answer: \n", + "\n", + "In the list above, there are non-zero elements and zero elements, sort the list in descending order, then move all the zeros elements behind the non-zero elements\n", + "'''" ] }, { @@ -181,11 +205,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ - "# Your answer here" + "# Your answer here\n", + "\n", + "example_1 = [1,3,4,0,2,0]\n", + "output_1 = [0,0,1,2,3,4]\n", + "\n", + "example_2 = [8,0,3,2,5]\n", + "output_2 = [0,2,3,5,8]\n", + "\n", + "\n", + "\n", + "\n" ] }, { @@ -198,11 +232,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 3, 5, 8, 0]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your answer here" + "\n", + "def move_zeros_to_end(nums: List[int]) -> List[int]:\n", + " total = len(nums)\n", + " \n", + " for i in range(total-1):\n", + " min_value = i\n", + " for j in range (i+1,total):\n", + " if nums[min_value]==0:\n", + " if nums[j] != 0:\n", + " min_value = j\n", + "\n", + "\n", + " else:\n", + " if nums[j] != 0 and nums[j]