Done puzzle 62
authorNeil Smith <neil.git@njae.me.uk>
Fri, 28 Apr 2017 18:20:02 +0000 (19:20 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Fri, 28 Apr 2017 18:20:02 +0000 (19:20 +0100)
euler62.ipynb [new file with mode: 0644]

diff --git a/euler62.ipynb b/euler62.ipynb
new file mode 100644 (file)
index 0000000..cf2d377
--- /dev/null
@@ -0,0 +1,153 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "true"
+      ]
+     },
+     "execution_count": 1,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "require_relative 'array-numbers'"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 52,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "865"
+      ]
+     },
+     "execution_count": 52,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "cubes = Hash.new {|h, k| h[k] = []}\n",
+    "cube_roots = {}\n",
+    "(100..1000).each do |i|\n",
+    "  c = (i ** 3)\n",
+    "  p = c.to_digits.sort.join\n",
+    "  # cubes[p] = (cubes[p] + [c])\n",
+    "  cubes[p] << c\n",
+    "  cube_roots[c] = i\n",
+    "end\n",
+    "cubes.length"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 53,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "{\"01234566\"=>[41063625, 56623104, 66430125]}"
+      ]
+     },
+     "execution_count": 53,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "cubes.select {|k, v| v.length >= 3}"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 42,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "345"
+      ]
+     },
+     "execution_count": 42,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "cube_roots[41063625]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 58,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "127035954683"
+      ]
+     },
+     "execution_count": 58,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "target = 5\n",
+    "\n",
+    "cubes = Hash.new {|h, k| h[k] = []}\n",
+    "finished = false\n",
+    "i = 100\n",
+    "while ! finished\n",
+    "  c = (i ** 3)\n",
+    "  p = c.to_digits.sort.join\n",
+    "  cubes[p] << c\n",
+    "  if cubes[p].length == target\n",
+    "    finished = true\n",
+    "  else\n",
+    "    i += 1\n",
+    "  end\n",
+    "end\n",
+    "\n",
+    "cubes[p].min"
+   ]
+  },
+  {
+   "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
+}