Done puzzle 58
authorNeil Smith <neil.git@njae.me.uk>
Wed, 12 Apr 2017 09:40:15 +0000 (10:40 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Wed, 12 Apr 2017 09:40:15 +0000 (10:40 +0100)
euler57.ipynb [new file with mode: 0644]

diff --git a/euler57.ipynb b/euler57.ipynb
new file mode 100644 (file)
index 0000000..1ebb681
--- /dev/null
@@ -0,0 +1,70 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "$f(n) = 1 + \\frac{1}{1 + f(n-1)}$\n",
+    "\n",
+    "$f(1) = \\frac{3}{2}$\n",
+    "\n",
+    "$f(2) = 1 + \\frac{1}{1 + f(1)} = 1 + \\frac{1}{1 + \\frac{3}{2}} = 1 + \\frac{1}{\\frac{5}{2}} = 1 + \\frac{2}{5} = \\frac{7}{5}$\n",
+    "\n",
+    "$f(3) = 1 + \\frac{1}{1 + f(2)} = 1 + \\frac{1}{1 + \\frac{7}{5}} = 1 + \\frac{1}{\\frac{12}{5}} = 1 + \\frac{5}{12} = \\frac{17}{12}$\n",
+    "\n",
+    "$f(n) = 1 + \\frac{1}{1 + \\frac{n}{d}} = 1 + \\frac{1}{\\frac{n+d}{d}} = 1 + \\frac{d}{n+d} = \\frac{n+2d}{n+d}$"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "153"
+      ]
+     },
+     "execution_count": 11,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "count = 0\n",
+    "n, d = 3, 2\n",
+    "(1..1000).each do\n",
+    "  # puts \"#{n}, #{d}, #{n.to_s.length > d.to_s.length}\"\n",
+    "  count += 1 if n.to_s.length > d.to_s.length\n",
+    "  n, d = n + 2 * d, n + d\n",
+    "end\n",
+    "count"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Ruby 2.4.0",
+   "language": "ruby",
+   "name": "ruby"
+  },
+  "language_info": {
+   "file_extension": ".rb",
+   "mimetype": "application/x-ruby",
+   "name": "ruby",
+   "version": "2.4.0"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}