19 "output_type": "execute_result"
24 "$primes = Primes.instance\n",
25 "$primes[10000] # returns the 10,001st prime"
43 "output_type": "execute_result"
47 "(0...(0+3)).map{|i| $primes[i]}"
65 "output_type": "execute_result"
69 "def prime_slice(start, len)\n",
70 " (start...(start + len)).map{|i| $primes[i]}\n",
89 "output_type": "execute_result"
93 "def sum_primes(start, len)\n",
94 " prime_slice(start, len).sum\n",
100 "execution_count": 5,
111 "execution_count": 5,
113 "output_type": "execute_result"
122 "execution_count": 6,
133 "execution_count": 6,
135 "output_type": "execute_result"
144 "execution_count": 8,
156 "execution_count": 8,
158 "output_type": "execute_result"
162 "sum_limit = 10**6\n",
167 "while $primes[start] <= sum_limit\n",
170 " sp = sum_primes(start, length)\n",
171 " while sp <= sum_limit\n",
172 " if sp.prime? && length > best_length\n",
173 " best_start = start\n",
174 " best_length = length\n",
175 " # puts \"#{start} - #{length} : #{sum_primes(start, length)}\"\n",
178 " sp = sum_primes(start, length)\n",
182 "[best_start, best_length, sum_primes(best_start, best_length)]"
187 "execution_count": null,
197 "display_name": "Ruby 2.4.0",
202 "file_extension": ".rb",
203 "mimetype": "application/x-ruby",