Skip to content

Instantly share code, notes, and snippets.

@romero-jose
Last active October 16, 2022 21:00
Show Gist options
  • Save romero-jose/c9c20b7522ca44e02008297d580ea3f0 to your computer and use it in GitHub Desktop.
Save romero-jose/c9c20b7522ca44e02008297d580ea3f0 to your computer and use it in GitHub Desktop.
Test.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Test.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyPxdyrLNhoeJXcgSNUegNLH",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"bb73c7d2ba054a54809f87e1aae37095": {
"model_module": "jupyter-dsvisualizer",
"model_name": "OperationsModel",
"model_module_version": "^0.1.7",
"state": {
"_dom_classes": [],
"_model_module": "jupyter-dsvisualizer",
"_model_module_version": "^0.1.7",
"_model_name": "OperationsModel",
"_view_count": null,
"_view_module": "jupyter-dsvisualizer",
"_view_module_version": "^0.1.7",
"_view_name": "OperationsView",
"layout": "IPY_MODEL_c50bd573a4dd46c58ea8bf744c794fe3",
"operations": {
"operations": [
{
"operation": {
"operation": "init",
"id": 163,
"value": "1",
"next": null
},
"metadata": {
"animate": false,
"source": [
"l.push(1)\n",
" 11 \n",
" 12 def push(self, value):\n",
"> 13 self.node = Node(value, self.node)\n",
" 14 \n",
" 15 def append(self, value):\n"
]
}
},
{
"operation": {
"operation": "init",
"id": 164,
"value": "2",
"next": 163
},
"metadata": {
"animate": false,
"source": [
"l.push(2)\n",
" 11 \n",
" 12 def push(self, value):\n",
"> 13 self.node = Node(value, self.node)\n",
" 14 \n",
" 15 def append(self, value):\n"
]
}
},
{
"operation": {
"operation": "init",
"id": 165,
"value": "3",
"next": 164
},
"metadata": {
"animate": false,
"source": [
"l.push(3)\n",
" 11 \n",
" 12 def push(self, value):\n",
"> 13 self.node = Node(value, self.node)\n",
" 14 \n",
" 15 def append(self, value):\n"
]
}
},
{
"operation": {
"operation": "get_next",
"id": 165
},
"metadata": {
"animate": true,
"source": [
"l.append(4)\n",
" 19 return\n",
" 20 \n",
"> 21 next = node.next\n",
" 22 while next is not None:\n",
" 23 node = next\n"
]
}
},
{
"operation": {
"operation": "get_next",
"id": 164
},
"metadata": {
"animate": true,
"source": [
"l.append(4)\n",
" 22 while next is not None:\n",
" 23 node = next\n",
"> 24 next = next.next\n",
" 25 node.next = Node(value, None)\n",
" 26 \n"
]
}
},
{
"operation": {
"operation": "get_next",
"id": 163
},
"metadata": {
"animate": true,
"source": [
"l.append(4)\n",
" 22 while next is not None:\n",
" 23 node = next\n",
"> 24 next = next.next\n",
" 25 node.next = Node(value, None)\n",
" 26 \n"
]
}
},
{
"operation": {
"operation": "init",
"id": 166,
"value": "4",
"next": null
},
"metadata": {
"animate": true,
"source": [
"l.append(4)\n",
" 23 node = next\n",
" 24 next = next.next\n",
"> 25 node.next = Node(value, None)\n",
" 26 \n",
" 27 def reverse(self):\n"
]
}
},
{
"operation": {
"operation": "set_next",
"id": 163,
"next": 166
},
"metadata": {
"animate": true,
"source": [
"l.append(4)\n",
" 23 node = next\n",
" 24 next = next.next\n",
"> 25 node.next = Node(value, None)\n",
" 26 \n",
" 27 def reverse(self):\n"
]
}
}
],
"metadata": {
"transition_duration": 1000,
"fade_in_duration": 500
}
}
}
},
"c50bd573a4dd46c58ea8bf744c794fe3": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"7b156ccd5b6143e6b39e0a412127fa5a": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/romero-jose/c9c20b7522ca44e02008297d580ea3f0/test.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"id": "igNybobewqlB"
},
"outputs": [],
"source": [
"!pip install dsvisualizer > /dev/null"
]
},
{
"cell_type": "code",
"source": [
"from google.colab import output\n",
"output.enable_custom_widget_manager()"
],
"metadata": {
"id": "BAx-oWlsxXEw"
},
"execution_count": 59,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from dsvisualizer import node, container, Logger"
],
"metadata": {
"id": "G55-3T2RwtW1"
},
"execution_count": 60,
"outputs": []
},
{
"cell_type": "code",
"source": [
"@node('value', 'next')\n",
"class Node:\n",
" def __init__(self, value, next=None):\n",
" self.value = value\n",
" self.next = next\n",
"\n",
"@container()\n",
"class List:\n",
" def __init__(self):\n",
" self.node = None\n",
"\n",
" def push(self, value):\n",
" self.node = Node(value, self.node)\n",
" \n",
" def append(self, value):\n",
" node = self.node\n",
" if node is None:\n",
" self.node = Node(value, None)\n",
" return\n",
"\n",
" next = node.next\n",
" while next is not None:\n",
" node = next\n",
" next = next.next\n",
" node.next = Node(value, None)\n",
"\n",
" def reverse(self):\n",
" prev = None\n",
" node = self.node\n",
" while(node is not None):\n",
" next = node.next\n",
" node.next = prev\n",
" prev = node\n",
" node = next\n",
" self.node = prev\n"
],
"metadata": {
"id": "y5w0MRhDw0wZ"
},
"execution_count": 76,
"outputs": []
},
{
"cell_type": "code",
"source": [
"l = List()\n",
"l.push(1)\n",
"l.push(2)\n",
"l.push(3)\n",
"l.visualize()\n",
"\n",
"l.append(4)\n",
"l.visualize(fade_in_duration=500)\n"
],
"metadata": {
"id": "TMRasj5eBrzP",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 481,
"referenced_widgets": [
"bb73c7d2ba054a54809f87e1aae37095",
"c50bd573a4dd46c58ea8bf744c794fe3",
"7b156ccd5b6143e6b39e0a412127fa5a"
]
},
"outputId": "28b6e732-4f72-4256-8ebb-6d57c38b7e7a"
},
"execution_count": 79,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"OperationsWidget(operations=Operations(operations=[Operation(operation=Init(id=163, value='1', next=None), met…"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "bb73c7d2ba054a54809f87e1aae37095"
}
},
"metadata": {
"application/vnd.jupyter.widget-view+json": {
"colab": {
"custom_widget_manager": {
"url": "https://ssl.gstatic.com/colaboratory-static/widgets/colab-cdn-widget-manager/d2e234f7cc04bf79/manager.min.js"
}
}
}
}
}
]
},
{
"cell_type": "code",
"source": [
"with Logger() as l:\n",
" "
],
"metadata": {
"id": "OLS3QMlnWaVV"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment