16 "execution_count": 45,
18 "output_type": "execute_result"
22 "load 'array-numbers.rb'"
27 "execution_count": 46,
38 "execution_count": 46,
40 "output_type": "execute_result"
44 "ch = (0..9999).flat_map {|i| i.to_digits}\n",
50 "execution_count": 47,
58 "[9, 7, 9, 9, 9, 8, 9, 9, 9, 9]"
61 "execution_count": 47,
63 "output_type": "execute_result"
72 "execution_count": 48,
83 "execution_count": 48,
85 "output_type": "execute_result"
94 "execution_count": 49,
105 "execution_count": 49,
107 "output_type": "execute_result"
116 "execution_count": 50,
127 "execution_count": 50,
129 "output_type": "execute_result"
138 "execution_count": 51,
149 "execution_count": 51,
151 "output_type": "execute_result"
160 "execution_count": 52,
171 "execution_count": 52,
173 "output_type": "execute_result"
181 " if (i - 10) % 2 == 0 # tens\n",
182 " ((i - 10) / 2) / 10 + 1\n",
184 " # ((i - 11) / 2) % 10\n",
185 " ((i - 10) / 2) % 10\n",
188 " if (i - 190) % 3 == 0 #hundreds\n",
189 " ((i - 190) / 3) / 100 + 1\n",
190 " elsif (i - 190) % 3 == 1 # tens\n",
191 " (((i - 190) / 3) / 10) % 10\n",
193 " ((i - 190) / 3) % 10\n",
195 " elsif i < 38890\n",
196 " if (i - 2890) % 4 == 0 # thousands\n",
197 " ((i - 2890) / 4) / 1000 + 1\n",
198 " elsif (i - 2890) % 4 == 1 # hundreds\n",
199 " (((i - 2890) / 4) / 100) % 10\n",
200 " elsif (i - 2890) % 4 == 2 # tens\n",
201 " (((i - 2890) / 4) / 10) % 10\n",
203 " ((i - 2890) / 4) % 10\n",
213 "execution_count": 105,
221 "output_type": "stream",
242 "execution_count": 105,
244 "output_type": "execute_result"
248 "(2890..2900).each do |i|\n",
249 " puts \"#{champ i} :: #{ch[i]} (#{i})\"\n",
255 "execution_count": 95,
266 "execution_count": 95,
268 "output_type": "execute_result"
272 "(1..38889).all? {|i| champ(i) == ch[i]}"
277 "execution_count": 107,
288 "execution_count": 107,
290 "output_type": "execute_result"
294 "(1..38889).select {|i| champ(i) != ch[i]}"
299 "execution_count": 108,
310 "execution_count": 108,
312 "output_type": "execute_result"
316 "190 - 10 == 2 * 9 * 10 ** 1"
321 "execution_count": 109,
332 "execution_count": 109,
334 "output_type": "execute_result"
338 "2890 - 190 == 3 * 9 * 10 ** 2"
343 "execution_count": 110,
354 "execution_count": 110,
356 "output_type": "execute_result"
360 "38890 - 2890 == 4 * 9 * 10 ** 3"
365 "execution_count": 120,
373 "[1, 10, 190, 2890, 38890, 488890, 5888890]"
376 "execution_count": 120,
378 "output_type": "execute_result"
382 "# threshold, number of digits, offset\n",
383 "(1..6).map {|n| n * 9 * 10**(n-1)}.reduce([1, 0, 0]) {|ss, n| ss + [[ss[-1][0] + n]}"
388 "execution_count": 2,
396 "[1, 0, 0, [9], [189], [2889], [38889], [488889], [5888889]]"
399 "execution_count": 2,
401 "output_type": "execute_result"
405 "(1..6).map {|n| n * 9 * 10**(n-1)}.reduce([[1, 0, 0]]) {|ss, n| ss + [[ss[-1][0] + n, n, ]]}"
410 "execution_count": 7,
418 "[[0, 9], [1, 180], [2, 2700], [3, 36000], [4, 450000], [5, 5400000], [6, 63000000]]"
421 "execution_count": 7,
423 "output_type": "execute_result"
427 "(0..6).map {|n| [n, (n+1) * 9 * 10**n]}"
432 "execution_count": 20,
440 "[[0, 1, 1], [9, 0, 10], [189, 1, 190], [2889, 2, 2890], [38889, 3, 38890], [488889, 4, 488890], [5888889, 5, 5888890], [68888889, 6, 68888890]]"
443 "execution_count": 20,
445 "output_type": "execute_result"
449 "(0..6).map {|n| [n, (n+1) * 9 * 10**n]}.reduce([[0, 1, 1]]) {|ts, ns| ts + [[ts[-1][0] + ns[1], ns[0], ts[-1][2] + ns[1]]] }"
454 "execution_count": 94,
465 "execution_count": 94,
467 "output_type": "execute_result"
475 " while n >= limit\n",
478 " step = i * 9 * 10**(i-1)\n",
481 " unit = (n - offset) % i\n",
482 " digit = ((n - offset) / i) / (10 ** (i-(unit +1))) % 10\n",
483 " digit += 1 if unit == 0 && i != 1\n",
484 " # return i, limit, offset, unit, digit\n",
491 "execution_count": 91,
498 "output_type": "stream",
500 "1 : 1 :: [1, 10, 0, 0, 1]\n",
501 "2 : 2 :: [1, 10, 0, 0, 2]\n",
502 "3 : 3 :: [1, 10, 0, 0, 3]\n",
503 "4 : 4 :: [1, 10, 0, 0, 4]\n",
504 "5 : 5 :: [1, 10, 0, 0, 5]\n",
505 "6 : 6 :: [1, 10, 0, 0, 6]\n",
506 "7 : 7 :: [1, 10, 0, 0, 7]\n",
507 "8 : 8 :: [1, 10, 0, 0, 8]\n",
508 "9 : 9 :: [1, 10, 0, 0, 9]\n",
509 "10 : 1 :: [2, 190, 10, 0, 1]\n",
510 "11 : 0 :: [2, 190, 10, 1, 0]\n",
511 "12 : 1 :: [2, 190, 10, 0, 1]\n",
512 "13 : 1 :: [2, 190, 10, 1, 1]\n",
513 "14 : 1 :: [2, 190, 10, 0, 1]\n",
514 "15 : 2 :: [2, 190, 10, 1, 2]\n",
515 "16 : 1 :: [2, 190, 10, 0, 1]\n",
516 "17 : 3 :: [2, 190, 10, 1, 3]\n",
517 "18 : 1 :: [2, 190, 10, 0, 1]\n",
518 "19 : 4 :: [2, 190, 10, 1, 4]\n",
519 "20 : 1 :: [2, 190, 10, 0, 1]\n"
528 "execution_count": 91,
530 "output_type": "execute_result"
534 "(1..20).each do |i| puts \"#{i} : #{champ i} :: #{champ2 i}\" end"
539 "execution_count": 92,
546 "output_type": "stream",
548 "180 : 9 :: [2, 190, 10, 0, 9]\n",
549 "181 : 5 :: [2, 190, 10, 1, 5]\n",
550 "182 : 9 :: [2, 190, 10, 0, 9]\n",
551 "183 : 6 :: [2, 190, 10, 1, 6]\n",
552 "184 : 9 :: [2, 190, 10, 0, 9]\n",
553 "185 : 7 :: [2, 190, 10, 1, 7]\n",
554 "186 : 9 :: [2, 190, 10, 0, 9]\n",
555 "187 : 8 :: [2, 190, 10, 1, 8]\n",
556 "188 : 9 :: [2, 190, 10, 0, 9]\n",
557 "189 : 9 :: [2, 190, 10, 1, 9]\n",
558 "190 : 1 :: [3, 2890, 190, 0, 1]\n",
559 "191 : 0 :: [3, 2890, 190, 1, 0]\n",
560 "192 : 0 :: [3, 2890, 190, 2, 0]\n",
561 "193 : 1 :: [3, 2890, 190, 0, 1]\n",
562 "194 : 0 :: [3, 2890, 190, 1, 0]\n",
563 "195 : 1 :: [3, 2890, 190, 2, 1]\n",
564 "196 : 1 :: [3, 2890, 190, 0, 1]\n",
565 "197 : 0 :: [3, 2890, 190, 1, 0]\n",
566 "198 : 2 :: [3, 2890, 190, 2, 2]\n",
567 "199 : 1 :: [3, 2890, 190, 0, 1]\n",
568 "200 : 0 :: [3, 2890, 190, 1, 0]\n"
577 "execution_count": 92,
579 "output_type": "execute_result"
583 "(180..200).each do |i| puts \"#{i} : #{champ i} :: #{champ2 i}\" end"
588 "execution_count": 93,
595 "output_type": "stream",
597 "2880 : 6 :: [3, 2890, 190, 2, 6]\n",
598 "2881 : 9 :: [3, 2890, 190, 0, 9]\n",
599 "2882 : 9 :: [3, 2890, 190, 1, 9]\n",
600 "2883 : 7 :: [3, 2890, 190, 2, 7]\n",
601 "2884 : 9 :: [3, 2890, 190, 0, 9]\n",
602 "2885 : 9 :: [3, 2890, 190, 1, 9]\n",
603 "2886 : 8 :: [3, 2890, 190, 2, 8]\n",
604 "2887 : 9 :: [3, 2890, 190, 0, 9]\n",
605 "2888 : 9 :: [3, 2890, 190, 1, 9]\n",
606 "2889 : 9 :: [3, 2890, 190, 2, 9]\n",
607 "2890 : 1 :: [4, 38890, 2890, 0, 1]\n",
608 "2891 : 0 :: [4, 38890, 2890, 1, 0]\n",
609 "2892 : 0 :: [4, 38890, 2890, 2, 0]\n",
610 "2893 : 0 :: [4, 38890, 2890, 3, 0]\n",
611 "2894 : 1 :: [4, 38890, 2890, 0, 1]\n",
612 "2895 : 0 :: [4, 38890, 2890, 1, 0]\n",
613 "2896 : 0 :: [4, 38890, 2890, 2, 0]\n",
614 "2897 : 1 :: [4, 38890, 2890, 3, 1]\n",
615 "2898 : 1 :: [4, 38890, 2890, 0, 1]\n",
616 "2899 : 0 :: [4, 38890, 2890, 1, 0]\n",
617 "2900 : 0 :: [4, 38890, 2890, 2, 0]\n"
626 "execution_count": 93,
628 "output_type": "execute_result"
632 "(2880..2900).each do |i| puts \"#{i} : #{champ i} :: #{champ2 i}\" end"
637 "execution_count": 96,
648 "execution_count": 96,
650 "output_type": "execute_result"
654 "(1..38889).all? {|i| champ2(i) == ch[i]}"
659 "execution_count": 99,
670 "execution_count": 99,
672 "output_type": "execute_result"
676 "(0..6).map {|e| champ2(10**e)}.reduce(:*)"
681 "execution_count": null,
691 "display_name": "Ruby 2.4.0",
696 "file_extension": ".rb",
697 "mimetype": "application/x-ruby",