Created
June 9, 2018 12:21
-
-
Save ShivangiM/bf14674aae352900922630b6413c48b2 to your computer and use it in GitHub Desktop.
Visualizing_PallindromNumbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"x_data = []\n", | |
"y_data = []\n", | |
"p_data = []" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# for n in range(, 4):\n", | |
"def f(n):\n", | |
" low = 10**(n-1)\n", | |
" high = 10**(n)\n", | |
" mx = 0\n", | |
" for i in range(low, high):\n", | |
" for j in range(low, high):\n", | |
" p = str(i*j)\n", | |
" if p == p[::-1]:\n", | |
" if (i*j) not in p_data:\n", | |
" x_data.append(i)\n", | |
" y_data.append(j)\n", | |
" p_data.append(i*j)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for n in range(2,4):\n", | |
" x = f(n)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"High five! You successfully sent some data to your account on plotly. View your plot in your browser at https://plot.ly/~danbo_95/0 or inside your plot.ly account where it is named 'basic-scatter'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~danbo_95/0.embed\" height=\"525px\" width=\"100%\"></iframe>" | |
], | |
"text/plain": [ | |
"<plotly.tools.PlotlyDisplay object>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import plotly\n", | |
"import plotly.plotly as py\n", | |
"import plotly.graph_objs as go\n", | |
"plotly.tools.set_credentials_file(username='', api_key='')\n", | |
"\n", | |
"# Create a trace\n", | |
"trace = go.Scatter(\n", | |
" x = x_data,\n", | |
" y = y_data,\n", | |
" mode = 'markers'\n", | |
")\n", | |
"\n", | |
"data = [trace]\n", | |
"\n", | |
"# Plot and embed in ipython notebook!\n", | |
"py.iplot(data, filename='basic-scatter')\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"906609" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"max(p_data)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~danbo_95/2.embed\" height=\"525px\" width=\"100%\"></iframe>" | |
], | |
"text/plain": [ | |
"<plotly.tools.PlotlyDisplay object>" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"tracex = go.Histogram(\n", | |
" x=x_data\n", | |
")\n", | |
"tracey = go.Histogram(\n", | |
" x=y_data\n", | |
")\n", | |
"data = [tracex, tracey]\n", | |
"layout = go.Layout(barmode='stack')\n", | |
"fig = go.Figure(data=data, layout=layout)\n", | |
"\n", | |
"py.iplot(fig, filename='stacked histogram')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Things to notice for max numbers:\n", | |
" 1) Odd numbers\n", | |
" 2) Corresponding product length even" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.15" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Author
ShivangiM
commented
Jun 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment