16 "execution_count": 66,
18 "output_type": "execute_result"
23 "require 'awesome_print'"
36 "[1, 2, 3, 4, 5, 6, 7, 8, 9]"
41 "output_type": "execute_result"
45 "digits = (1..9).to_a"
50 "execution_count": 88,
61 "execution_count": 88,
63 "output_type": "execute_result"
69 " return enum_for(:subbags, n) unless block_given?\n",
73 " (0..self.length).each do |i|\n",
74 " self.combination(i).each do |f|\n",
75 " (self - f).subbags(n-1).each do |r|\n",
83 " def full_subbags(n)\n",
84 " return enum_for(:full_subbags, n) unless block_given?\n",
85 " self.subbags(n).select {|bags| bags.none? {|b| b.empty?}}.each do |bs|\n",
94 "execution_count": 89,
101 "output_type": "stream",
108 "[1,2,3].subbags(1) {|i| puts i}"
113 "execution_count": 90,
124 "execution_count": 90,
126 "output_type": "execute_result"
130 "[1,2,3].subbags(1).to_a"
135 "execution_count": 91,
142 "output_type": "stream",
160 "execution_count": 91,
162 "output_type": "execute_result"
166 "[1,2,3].subbags(2) {|i| puts i}"
171 "execution_count": 92,
179 "[[[], [1, 2, 3]], [[1], [2, 3]], [[2], [1, 3]], [[3], [1, 2]], [[1, 2], [3]], [[1, 3], [2]], [[2, 3], [1]], [[1, 2, 3], []]]"
182 "execution_count": 92,
184 "output_type": "execute_result"
188 "[1,2,3].subbags(2).to_a"
193 "execution_count": 93,
204 "execution_count": 93,
206 "output_type": "execute_result"
210 "[1,2,3].subbags(2).to_a.length"
215 "execution_count": 94,
223 "[[[], [], [1, 2, 3]], [[], [1], [2, 3]], [[], [2], [1, 3]], [[], [3], [1, 2]], [[], [1, 2], [3]], [[], [1, 3], [2]], [[], [2, 3], [1]], [[], [1, 2, 3], []], [[1], [], [2, 3]], [[1], [2], [3]], [[1], [3], [2]], [[1], [2, 3], []], [[2], [], [1, 3]], [[2], [1], [3]], [[2], [3], [1]], [[2], [1, 3], []], [[3], [], [1, 2]], [[3], [1], [2]], [[3], [2], [1]], [[3], [1, 2], []], [[1, 2], [], [3]], [[1, 2], [3], []], [[1, 3], [], [2]], [[1, 3], [2], []], [[2, 3], [], [1]], [[2, 3], [1], []], [[1, 2, 3], [], []]]"
226 "execution_count": 94,
228 "output_type": "execute_result"
232 "[1,2,3].subbags(3).to_a"
237 "execution_count": 95,
248 "execution_count": 95,
250 "output_type": "execute_result"
254 "[1,2,3].subbags(3).to_a.length"
259 "execution_count": 96,
266 "output_type": "stream",
275 "i: 3, f: [1, 2, 3]\n"
284 "execution_count": 96,
286 "output_type": "execute_result"
290 "(0..[1,2,3].length).each do |i|\n",
291 " [1,2,3].combination(i).each do |f|\n",
292 " puts \"i: #{i}, f: #{f}\"\n",
299 "execution_count": 97,
307 "[[[1], [2], [3, 4]], [[1], [3], [2, 4]], [[1], [4], [2, 3]], [[1], [2, 3], [4]], [[1], [2, 4], [3]], [[1], [3, 4], [2]], [[2], [1], [3, 4]], [[2], [3], [1, 4]], [[2], [4], [1, 3]], [[2], [1, 3], [4]], [[2], [1, 4], [3]], [[2], [3, 4], [1]], [[3], [1], [2, 4]], [[3], [2], [1, 4]], [[3], [4], [1, 2]], [[3], [1, 2], [4]], [[3], [1, 4], [2]], [[3], [2, 4], [1]], [[4], [1], [2, 3]], [[4], [2], [1, 3]], [[4], [3], [1, 2]], [[4], [1, 2], [3]], [[4], [1, 3], [2]], [[4], [2, 3], [1]], [[1, 2], [3], [4]], [[1, 2], [4], [3]], [[1, 3], [2], [4]], [[1, 3], [4], [2]], [[1, 4], [2], [3]], [[1, 4], [3], [2]], [[2, 3], [1], [4]], [[2, 3], [4], [1]], [[2, 4], [1], [3]], [[2, 4], [3], [1]], [[3, 4], [1], [2]], [[3, 4], [2], [1]]]"
310 "execution_count": 97,
312 "output_type": "execute_result"
316 "[1,2,3,4].full_subbags(3).to_a"
321 "execution_count": 98,
332 "execution_count": 98,
334 "output_type": "execute_result"
338 "digits.full_subbags(3).to_a.length"
343 "execution_count": 78,
354 "execution_count": 78,
356 "output_type": "execute_result"
360 "def euler_product(subbags)\n",
362 " a, b, c = subbags\n",
364 " a.permutation.each do |ap|\n",
365 " an = ap.map {|d| d.to_s}.join.to_i\n",
366 " b.permutation.each do |bp|\n",
367 " bn = bp.map {|d| d.to_s}.join.to_i\n",
369 " cp = cn.to_s.split('').map {|d| d.to_i}\n",
370 " if cp.sort == csort\n",
381 "execution_count": 54,
392 "execution_count": 54,
394 "output_type": "execute_result"
398 "[1,2,3].map {|d| d.to_s}.join.to_i"
403 "execution_count": 58,
414 "execution_count": 58,
416 "output_type": "execute_result"
420 "123.to_s.split('').map {|d| d.to_i}"
425 "execution_count": 85,
437 "execution_count": 85,
439 "output_type": "execute_result"
443 "[1,2,3,4].full_subbags(3).flat_map {|bs| euler_product bs}.to_set"
448 "execution_count": 83,
459 "execution_count": 83,
461 "output_type": "execute_result"
465 "euler_product([[3, 9], [1, 8, 6], [7, 2, 5, 4]])"
470 "execution_count": 87,
482 "execution_count": 87,
484 "output_type": "execute_result"
488 "digits.full_subbags(3).flat_map {|bs| euler_product bs}.to_set.sum"
493 "execution_count": null,
503 "display_name": "Ruby 2.4.0",
508 "file_extension": ".rb",
509 "mimetype": "application/x-ruby",