Skip to content

Instantly share code, notes, and snippets.

@veretennikovalexey
Created June 29, 2022 16:34
Show Gist options
  • Save veretennikovalexey/e3d740346a6efce4fdf83ece8fa93d15 to your computer and use it in GitHub Desktop.
Save veretennikovalexey/e3d740346a6efce4fdf83ece8fa93d15 to your computer and use it in GitHub Desktop.
collatz.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "collatz.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyNntcSsAvAI7c40wIG8H1bY",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/veretennikovalexey/e3d740346a6efce4fdf83ece8fa93d15/collatz.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ge5oaJT8S79U",
"outputId": "313241b3-6e28-4375-bc93-ecf37665c597"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"19\n",
"58\n",
"29\n",
"88\n",
"44\n",
"22\n",
"11\n",
"34\n",
"17\n",
"52\n",
"26\n",
"13\n",
"40\n",
"20\n",
"10\n",
"5\n",
"16\n",
"8\n",
"4\n",
"2\n",
"1\n"
]
}
],
"source": [
"number = int( input() )\n",
"while number != 1 :\n",
" if number % 2 == 0 :\n",
" number = number // 2\n",
" elif number % 2 == 1 :\n",
" number = number * 3 + 1\n",
" print( number )\n",
"\n"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment