Skip to content

Instantly share code, notes, and snippets.

@vors
Created April 17, 2021 03:58
Show Gist options
  • Save vors/d294ea1709c8f3d31c7aea8272cb2982 to your computer and use it in GitHub Desktop.
Save vors/d294ea1709c8f3d31c7aea8272cb2982 to your computer and use it in GitHub Desktop.
hello.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The intuition is that it's useful to solve the following equation."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"x = 808017424794512875886459904961710757005754368000000000"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[30, 6, 4, 10], [22, -2, 8, 8], [-16, -6, -5, -4], [8, 28, 10, 27]]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def exp(x):\n",
" res = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n",
" for i in range(0, 4):\n",
" for j in range(0, 4):\n",
" for k in range(0, 4):\n",
" res[i][j] += x[i][k] * x[k][j]\n",
" return res\n",
"\n",
"A = [[1, 3, 2, 4], [3, 1, 4, 2], [2, -4, 1, -2], [4, 2, -3, 1]]\n",
"exp(A)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"class Matrix:\n",
" def __init__(self, x):\n",
" self.A = x\n",
" \n",
" def mult(self, B):\n",
" res = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n",
" for i in range(0, 4):\n",
" for j in range(0, 4):\n",
" for k in range(0, 4):\n",
" res[i][j] += self.A[i][k] * B[k][j]\n",
" return Matrix(res)\n",
"\n",
"A = [\n",
" [1, 3, 2, 4],\n",
" [3, 1, 4, 2],\n",
" [2, -4, 1, -2],\n",
" [4, 2, -2, 1]\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"m = Matrix(A)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1024\n",
"2048\n",
"3072\n",
"4096\n",
"5120\n",
"6144\n",
"7168\n",
"8192\n",
"9216\n",
"10240\n",
"11264\n",
"12288\n",
"13312\n",
"14336\n",
"15360\n",
"16384\n",
"17408\n",
"18432\n",
"19456\n",
"20480\n",
"21504\n",
"22528\n",
"23552\n",
"24576\n",
"25600\n",
"26624\n",
"27648\n",
"28672\n",
"29696\n",
"30720\n",
"31744\n",
"32768\n",
"33792\n",
"34816\n",
"35840\n",
"36864\n",
"37888\n",
"38912\n",
"39936\n",
"40960\n",
"41984\n",
"43008\n",
"44032\n",
"45056\n",
"46080\n",
"47104\n",
"48128\n",
"49152\n",
"50176\n",
"51200\n",
"52224\n",
"53248\n",
"54272\n",
"55296\n",
"56320\n",
"57344\n",
"58368\n",
"59392\n",
"60416\n",
"61440\n",
"62464\n",
"63488\n",
"64512\n",
"65536\n",
"66560\n",
"67584\n",
"68608\n",
"69632\n",
"70656\n",
"71680\n",
"72704\n",
"73728\n",
"74752\n",
"75776\n",
"76800\n",
"77824\n",
"78848\n",
"79872\n",
"80896\n",
"81920\n",
"82944\n",
"83968\n",
"84992\n",
"86016\n",
"87040\n",
"88064\n",
"89088\n",
"90112\n",
"91136\n",
"92160\n",
"93184\n",
"94208\n",
"95232\n",
"96256\n",
"97280\n",
"98304\n",
"99328\n",
"100352\n",
"101376\n",
"102400\n",
"103424\n",
"104448\n"
]
}
],
"source": [
"from itertools import chain\n",
"B = Matrix(A)\n",
"is_done = False\n",
"counter = 0\n",
"while True:\n",
" B = B.mult(A)\n",
" new_world = list(chain.from_iterable(B.A))\n",
" if x in new_world:\n",
" print(\"Hello World!\")\n",
" is_done = True\n",
" break\n",
" counter += 1\n",
" if counter % 1024 == 0:\n",
" print(counter)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment