{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# a bonary tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#***********************************************************************\n",
    "#**                  a bo-binary tree                                  *\n",
    "#** for and inspired by Wang Xiaobo (1952-1997), writer and programmer.*\n",
    "#**    \"我也自做了词组功能，是棵B树，我觉得自写的软件自用，感觉是最好的。\"        *\n",
    "#**    \"I created a word feature with a binary tree strucutre,         *\n",
    "#**    and I feel best about using a program you created yourself.\"    *\n",
    "#**    read more in archival documentation(Chinese):                   *\n",
    "#**    https://blog.csdn.net/weixin_33697898/article/details/93356187  *\n",
    "#**                                                                    *\n",
    "#***********************************************************************"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 思维的乐趣 \n",
    "### on discourse \n",
    "### quotes from 《我的精神家园》\n",
    "谈到思想的乐趣，我就想到我父亲的遭遇。我父亲是一位哲学教授，在五六十年代从事思维史的研究。在老年时，他告诉我自己一生的学术经历，就如一部恐怖电影。每当他企图立论时，总要在大一统的思想体系里找到自己的位置，就如一只老母鸡要在一个大搬家的宅院里找地方孵蛋一样。结果他虽然热爱科学而且很努力，在一生中却没有得到思维的乐趣，之收获了无数的恐慌。他一生的探索，只剩下了一些断壁残垣，收到一本名为《逻辑探索》的书里，在他身后出版。\n",
    "\n",
    "我在沉默中过了很多年：插队、当工人、当大学生，后来又在大学里任过教。当教师的人保持沉默似不可能，但我教的是技术性的课程，在讲台上只讲技术性的话，下了课我就走人。找我看，不管干什么都可以保持沉默。当然，我还有一个终身爱好，就是写小说。但是写好了不拿去发表，同样也保持了沉默。至于沉默的理由，很是简单。那就是信不过话语圈。从我短短的人生经历看，它是一座声名狼藉的疯人院。当时我怀疑的不是说过亩产三十万斤粮、炸过精神原子弹的那个话语圈，而是一切话语圈子。\n",
    "\n",
    "还有一些人，因为种种原因，对于话语的世界有某种厌恶之情。我属于这最后一种。作为最后一种人，也有义务谈自己的所见所闻。\n",
    "\n",
    "王小波（1997).《我的精神家园》.北京：文化艺术出版社.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create a proof of concept dictionary tree that looks for hong(3) fu(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from anytree import Node, RenderTree\n",
    "h = Node(\"h\")\n",
    "o = Node(\"o\", parent=h)\n",
    "n = Node(\"n\", parent=o)\n",
    "g = Node(\"g\", parent=n)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Node('/h')\n",
      "Node('/h/o/n/g')\n",
      "h\n",
      "└── o\n",
      "    └── n\n",
      "        └── g\n"
     ]
    }
   ],
   "source": [
    "#print node\n",
    "print(h)\n",
    "print(g)\n",
    "\n",
    "#print tree\n",
    "for pre, fill, node in RenderTree(h):\n",
    "\tprint(\"%s%s\" %(pre,node.name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f\n",
      "└── u\n"
     ]
    }
   ],
   "source": [
    "f = Node(\"f\")\n",
    "u = Node(\"u\", parent = f)\n",
    "for pre, fill, node in RenderTree(f):\n",
    "\tprint(\"%s%s\" %(pre,node.name))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y\n",
      "└── e\n"
     ]
    }
   ],
   "source": [
    "y = Node(\"y\")\n",
    "e = Node(\"e\", parent = y)\n",
    "for pre, fill, node in RenderTree(y):\n",
    "\tprint(\"%s%s\" %(pre,node.name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b\n",
      "└── e\n",
      "    └── n\n"
     ]
    }
   ],
   "source": [
    "b = Node(\"b\")\n",
    "e = Node(\"e\", parent = b)\n",
    "n = Node(\"n\", parent = e)\n",
    "for pre, fill, node in RenderTree(b):\n",
    "\tprint(\"%s%s\" %(pre,node.name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def printTree(root):\n",
    "    for pre, fill, node in RenderTree(root):\n",
    "        print(\"%s%s\" %(pre,node.name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n",
      "└── o\n",
      "    └── n\n",
      "        └── g\n",
      "红\n",
      "\n",
      "f\n",
      "└── u\n",
      "拂\n",
      "\n",
      "y\n",
      "└── e\n",
      "夜\n",
      "\n",
      "b\n",
      "└── e\n",
      "    └── n\n",
      "奔\n",
      "\n"
     ]
    }
   ],
   "source": [
    "tree_list = [h,f,y,b]\n",
    "红拂夜奔 = [\"红\",\"拂\",\"夜\",\"奔\"]\n",
    "counter = 0\n",
    "for tree in tree_list:\n",
    "    printTree(tree)\n",
    "    print(红拂夜奔[counter])\n",
    "    counter = counter + 1\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# an alphabet binary search tree\n",
    "import string\n",
    "alphabet_s = string.ascii_lowercase\n",
    "alphabet_l = list(alphabet_s)\n",
    "#print(alphabet_l)\n",
    "# add nodes manually, starting from m "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<video src=\"vid/wang_interview.mp4\" controls  >\n",
       "      Your browser does not support the <code>video</code> element.\n",
       "    </video>"
      ],
      "text/plain": [
       "<IPython.core.display.Video object>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import IPython.display \n",
    "Video('vid/wang_interview.mp4')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# transcription of wang's interview in Chinese\n",
    "# autotranslate that into English for non-Chinese readers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据结构是思维的形状的一种表现方式\n",
    "the structure of data may be one representation of the form of thought "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Wang Xiaobo (1952-1997), writer and programmer. <br>\n",
    "\"我也自做了词组功能，是棵B树，我觉得自写的软件自用，感觉是最好的。\" <br>\n",
    "\"I created a word feature with a binary tree strucutre, and I feel best about using a program you created yourself.\"\n",
    "read more in archival documentation(Chinese):<br>\n",
    "https://blog.csdn.net/weixin_33697898/article/details/93356187"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
