13 " (1..self).inject(:*) || 1\n",
15 " alias :! :factorial\n",
21 "execution_count": 11,
32 "execution_count": 11,
34 "output_type": "execute_result"
40 " self.to_s.split('').map {|d| d.to_i}\n",
60 "output_type": "execute_result"
82 "output_type": "execute_result"
102 "execution_count": 8,
104 "output_type": "execute_result"
113 "execution_count": 10,
120 "output_type": "stream",
122 "1, 362880, 10, false\n",
123 "2, 725760, 100, false\n",
124 "3, 1088640, 1000, false\n",
125 "4, 1451520, 10000, false\n",
126 "5, 1814400, 100000, false\n",
127 "6, 2177280, 1000000, false\n",
128 "7, 2540160, 10000000, true\n",
129 "8, 2903040, 100000000, true\n",
130 "9, 3265920, 1000000000, true\n",
131 "10, 3628800, 10000000000, true\n"
140 "execution_count": 10,
142 "output_type": "execute_result"
146 "(1..10).each do |i|\n",
147 " puts \"#{i}, #{i * 9.!}, #{10 ** i}, #{i * 9.! < 10 ** i}\"\n",
153 "execution_count": 12,
161 "[3, 4, 5, 6, 7, 8, 9, 10]"
164 "execution_count": 12,
166 "output_type": "execute_result"
175 "execution_count": 13,
186 "execution_count": 13,
188 "output_type": "execute_result"
192 "def factorial_sum?(n)\n",
193 " n.to_digits.map {|d| d.!}.reduce(:+) == n\n",
199 "execution_count": 14,
210 "execution_count": 14,
212 "output_type": "execute_result"
216 "145.to_digits.map {|d| d.!}.reduce(:+)"
221 "execution_count": 15,
232 "execution_count": 15,
234 "output_type": "execute_result"
238 "146.to_digits.map {|d| d.!}.reduce(:+)"
243 "execution_count": 16,
254 "execution_count": 16,
256 "output_type": "execute_result"
265 "execution_count": 17,
276 "execution_count": 17,
278 "output_type": "execute_result"
287 "execution_count": 18,
298 "execution_count": 18,
300 "output_type": "execute_result"
304 "(3..1000).select {|n| factorial_sum? n}.to_a"
309 "execution_count": 19,
320 "execution_count": 19,
322 "output_type": "execute_result"
326 "(3..10**7).select {|n| factorial_sum? n}.to_a"
331 "execution_count": 20,
342 "execution_count": 20,
344 "output_type": "execute_result"
348 "(3..10**7).select {|n| factorial_sum? n}.sum"
353 "execution_count": null,
363 "display_name": "Ruby 2.4.0",
368 "file_extension": ".rb",
369 "mimetype": "application/x-ruby",