Created
January 17, 2020 01:12
-
-
Save LuxXx/0b4b1f57ced3b4796741284a4af355fb to your computer and use it in GitHub Desktop.
Project Euler Problem 65
This file contains hidden or 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 sympy\n", | |
| "import numpy as np" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "arr = np.array([2, 1])\n", | |
| "for k in range(1,100):\n", | |
| " arr = np.append(arr, [2*k, 1, 1])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/latex": [ | |
| "$\\displaystyle \\frac{6963524437876961749120273824619538346438023188214475670667}{2561737478789858711161539537921323010415623148113041714756}$" | |
| ], | |
| "text/plain": [ | |
| "6963524437876961749120273824619538346438023188214475670667/2561737478789858711161539537921323010415623148113041714756" | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "one = sympy.symbols('1')\n", | |
| "p = sympy.symbols('p')\n", | |
| "\n", | |
| "def pack(e, z):\n", | |
| " return e.subs(p, z + 1 / p)\n", | |
| "t = p\n", | |
| "\n", | |
| "for k in arr[0:99]:\n", | |
| " t = pack(t, k)\n", | |
| "t.replace(p, 1).simplify()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "6963524437876961749120273824619538346438023188214475670667/2561737478789858711161539537921323010415623148113041714756\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(t.replace(p, 1).simplify())" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "272" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "s = 0\n", | |
| "for k in '6963524437876961749120273824619538346438023188214475670667':\n", | |
| " s+=int(k)\n", | |
| "s" | |
| ] | |
| } | |
| ], | |
| "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.0" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment