Skip to content

Instantly share code, notes, and snippets.

@jtpio
Created April 20, 2016 21:25
Show Gist options
  • Save jtpio/42d0dcf87338041f7446877bd1f39a57 to your computer and use it in GitHub Desktop.
Save jtpio/42d0dcf87338041f7446877bd1f39a57 to your computer and use it in GitHub Desktop.
MathsJam April 2016 - Reverse Pairs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]\n"
]
}
],
"source": [
"N = 100\n",
"ns = list(range(N))\n",
"print(ns)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"12 x 42 = 21 x 24\n",
"12 x 63 = 21 x 36\n",
"12 x 84 = 21 x 48\n",
"13 x 62 = 31 x 26\n",
"13 x 93 = 31 x 39\n",
"14 x 82 = 41 x 28\n",
"21 x 24 = 12 x 42\n",
"21 x 36 = 12 x 63\n",
"21 x 48 = 12 x 84\n",
"23 x 64 = 32 x 46\n",
"23 x 96 = 32 x 69\n",
"24 x 63 = 42 x 36\n",
"24 x 84 = 42 x 48\n",
"26 x 31 = 62 x 13\n",
"26 x 93 = 62 x 39\n",
"28 x 41 = 82 x 14\n",
"31 x 39 = 13 x 93\n",
"32 x 46 = 23 x 64\n",
"32 x 69 = 23 x 96\n",
"34 x 86 = 43 x 68\n",
"36 x 42 = 63 x 24\n",
"36 x 84 = 63 x 48\n",
"39 x 62 = 93 x 26\n",
"42 x 48 = 24 x 84\n",
"43 x 68 = 34 x 86\n",
"46 x 96 = 64 x 69\n",
"48 x 63 = 84 x 36\n",
"64 x 69 = 46 x 96\n",
"Total: 28\n"
]
}
],
"source": [
"c = 0\n",
"for i in range(10, N):\n",
" for j in range(i + 1, N):\n",
" p = ns[i] * ns[j]\n",
" ri = int(str(ns[i])[::-1])\n",
" rj = int(str(ns[j])[::-1])\n",
" r = ri * rj\n",
" if p == r and ns[i] != ri and ns[i] != rj:\n",
" c += 1\n",
" print(ns[i], 'x', ns[j], '=', ri, 'x', rj)\n",
"print('Total:', c)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment