18 "output_type": "execute_result"
22 "require \"awesome_print\""
27 "execution_count": 91,
38 "execution_count": 91,
40 "output_type": "execute_result"
44 "def division(n, debug: false)\n",
47 " quotient = \"0.\"\n",
49 " while dividend != 0 && !(trail.include?(dividend))\n",
50 " q, r = dividend.divmod(divisor)\n",
51 " puts(\"#{dividend} #{divisor} #{q} #{r} #{!(trail.include?(dividend))} #{trail}\") if debug\n",
54 " quotient += \"0\"\n",
57 " trail += [dividend]\n",
58 " quotient += q.to_s\n",
59 " dividend = r * 10\n",
62 " if dividend != 0\n",
63 " cycle_length = trail.length - trail.rindex(dividend)\n",
65 " cycle_length = 0\n",
67 " # return quotient, cycle_length, trail + [dividend]\n",
87 "output_type": "execute_result"
107 "execution_count": 8,
109 "output_type": "execute_result"
113 "q, r = 10.divmod(8)"
118 "execution_count": 9,
129 "execution_count": 9,
131 "output_type": "execute_result"
135 "q, r = 20.divmod(8)"
140 "execution_count": 10,
151 "execution_count": 10,
153 "output_type": "execute_result"
157 "q, r = 40.divmod(8)"
162 "execution_count": 92,
173 "execution_count": 92,
175 "output_type": "execute_result"
184 "execution_count": 93,
195 "execution_count": 93,
197 "output_type": "execute_result"
206 "execution_count": 94,
217 "execution_count": 94,
219 "output_type": "execute_result"
228 "execution_count": 95,
235 "output_type": "stream",
290 "execution_count": 95,
292 "output_type": "execute_result"
296 "(2..46).each do |i| puts(\"#{i}: #{division(i)}\") end"
301 "execution_count": 99,
312 "execution_count": 99,
314 "output_type": "execute_result"
318 "(1..1000).max_by {|i| division(i)}"
323 "execution_count": 97,
334 "execution_count": 97,
336 "output_type": "execute_result"
345 "execution_count": null,
355 "display_name": "Ruby 2.4.0",
360 "file_extension": ".rb",
361 "mimetype": "application/x-ruby",