Martin Gardner のlucky number について
2187 + 1234 = 3421
2187 + 12345 = 14532
2187 + 123456 = 125643
2187 + 1234567 = 1236754
2187 + 12345678 = 12347865
2187 + 123456789 = 123458976
のうち、
2187 + 1234 = 3421
2187 + 2345 = 4532
2187 + 3456 = 5643
2187 + 4567 = 6754
2187 + 5678 = 7865
2187 + 6789 = 8976
2187 + 2345 = 4532
2187 + 3456 = 5643
2187 + 4567 = 6754
2187 + 5678 = 7865
2187 + 6789 = 8976
の部分が大事だと思うので、このような数字を見つけてみた。
出力結果
def A(digit)
ary = []
(10 ** (digit - 1)..10 ** digit - 1).each{|i|
flag = true
(1..10 - digit).each{|j|
a = (j..j + digit - 1).to_a
k = a.join.to_i
l = i + k
if l.to_s.split('').map(&:to_i).sort != a
flag = false
break
end
}
ary << i if flag
}
ary
end
def B(ary, digit)
p ary
puts
ary.each{|i|
(1..10 - digit).each{|j|
k = (j..j + digit - 1).to_a.join.to_i
puts "#{i} + #{k} = #{i + k}"
}
puts "-" * (digit * 3 + 6)
}
end
(1..5).each{|i| B(A(i), i)}
出力結果
[]
[]
[108, 189, 198]
108 + 123 = 231
108 + 234 = 342
108 + 345 = 453
108 + 456 = 564
108 + 567 = 675
108 + 678 = 786
108 + 789 = 897
---------------
189 + 123 = 312
189 + 234 = 423
189 + 345 = 534
189 + 456 = 645
189 + 567 = 756
189 + 678 = 867
189 + 789 = 978
---------------
198 + 123 = 321
198 + 234 = 432
198 + 345 = 543
198 + 456 = 654
198 + 567 = 765
198 + 678 = 876
198 + 789 = 987
---------------
[1080, 1107, 1179, 1197, 1890, 1908, 1980, 2007, 2178, 2187, 2889, 2898, 2979, 2997, 3078, 3087]
1080 + 1234 = 2314
1080 + 2345 = 3425
1080 + 3456 = 4536
1080 + 4567 = 5647
1080 + 5678 = 6758
1080 + 6789 = 7869
------------------
1107 + 1234 = 2341
1107 + 2345 = 3452
1107 + 3456 = 4563
1107 + 4567 = 5674
1107 + 5678 = 6785
1107 + 6789 = 7896
------------------
1179 + 1234 = 2413
1179 + 2345 = 3524
1179 + 3456 = 4635
1179 + 4567 = 5746
1179 + 5678 = 6857
1179 + 6789 = 7968
------------------
1197 + 1234 = 2431
1197 + 2345 = 3542
1197 + 3456 = 4653
1197 + 4567 = 5764
1197 + 5678 = 6875
1197 + 6789 = 7986
------------------
1890 + 1234 = 3124
1890 + 2345 = 4235
1890 + 3456 = 5346
1890 + 4567 = 6457
1890 + 5678 = 7568
1890 + 6789 = 8679
------------------
1908 + 1234 = 3142
1908 + 2345 = 4253
1908 + 3456 = 5364
1908 + 4567 = 6475
1908 + 5678 = 7586
1908 + 6789 = 8697
------------------
1980 + 1234 = 3214
1980 + 2345 = 4325
1980 + 3456 = 5436
1980 + 4567 = 6547
1980 + 5678 = 7658
1980 + 6789 = 8769
------------------
2007 + 1234 = 3241
2007 + 2345 = 4352
2007 + 3456 = 5463
2007 + 4567 = 6574
2007 + 5678 = 7685
2007 + 6789 = 8796
------------------
2178 + 1234 = 3412
2178 + 2345 = 4523
2178 + 3456 = 5634
2178 + 4567 = 6745
2178 + 5678 = 7856
2178 + 6789 = 8967
------------------
2187 + 1234 = 3421
2187 + 2345 = 4532
2187 + 3456 = 5643
2187 + 4567 = 6754
2187 + 5678 = 7865
2187 + 6789 = 8976
------------------
2889 + 1234 = 4123
2889 + 2345 = 5234
2889 + 3456 = 6345
2889 + 4567 = 7456
2889 + 5678 = 8567
2889 + 6789 = 9678
------------------
2898 + 1234 = 4132
2898 + 2345 = 5243
2898 + 3456 = 6354
2898 + 4567 = 7465
2898 + 5678 = 8576
2898 + 6789 = 9687
------------------
2979 + 1234 = 4213
2979 + 2345 = 5324
2979 + 3456 = 6435
2979 + 4567 = 7546
2979 + 5678 = 8657
2979 + 6789 = 9768
------------------
2997 + 1234 = 4231
2997 + 2345 = 5342
2997 + 3456 = 6453
2997 + 4567 = 7564
2997 + 5678 = 8675
2997 + 6789 = 9786
------------------
3078 + 1234 = 4312
3078 + 2345 = 5423
3078 + 3456 = 6534
3078 + 4567 = 7645
3078 + 5678 = 8756
3078 + 6789 = 9867
------------------
3087 + 1234 = 4321
3087 + 2345 = 5432
3087 + 3456 = 6543
3087 + 4567 = 7654
3087 + 5678 = 8765
3087 + 6789 = 9876
------------------
[10800, 10809, 11070, 11106, 11169, 11196, 11790, 11808, 11970, 12006, 12168, 12186, 12789, 12798, 12969, 12996, 13068, 13086, 18900, 18909, 19080, 19107, 19179, 19197, 19800, 19809, 20070, 20106, 20169, 20196, 21780, 21807, 21870, 21906, 22167, 22176, 22779, 22797, 22869, 22896, 23067, 23076, 28890, 28908, 28980, 29007, 29178, 29187, 29790, 29808, 29970, 30006, 30168, 30186, 30780, 30807, 30870, 30906, 31167, 31176, 32778, 32787, 32868, 32886, 32967, 32976, 38889, 38898, 38979, 38997, 39078, 39087, 39789, 39798, 39969, 39996, 40068, 40086, 40779, 40797, 40869, 40896, 41067, 41076, 41778, 41787, 41868, 41886, 41967, 41976]
10800 + 12345 = 23145
10800 + 23456 = 34256
10800 + 34567 = 45367
10800 + 45678 = 56478
10800 + 56789 = 67589
---------------------
10809 + 12345 = 23154
10809 + 23456 = 34265
10809 + 34567 = 45376
10809 + 45678 = 56487
10809 + 56789 = 67598
---------------------
11070 + 12345 = 23415
11070 + 23456 = 34526
11070 + 34567 = 45637
11070 + 45678 = 56748
11070 + 56789 = 67859
---------------------
11106 + 12345 = 23451
11106 + 23456 = 34562
11106 + 34567 = 45673
11106 + 45678 = 56784
11106 + 56789 = 67895
---------------------
11169 + 12345 = 23514
11169 + 23456 = 34625
11169 + 34567 = 45736
11169 + 45678 = 56847
11169 + 56789 = 67958
---------------------
11196 + 12345 = 23541
11196 + 23456 = 34652
11196 + 34567 = 45763
11196 + 45678 = 56874
11196 + 56789 = 67985
---------------------
11790 + 12345 = 24135
11790 + 23456 = 35246
11790 + 34567 = 46357
11790 + 45678 = 57468
11790 + 56789 = 68579
---------------------
11808 + 12345 = 24153
11808 + 23456 = 35264
11808 + 34567 = 46375
11808 + 45678 = 57486
11808 + 56789 = 68597
---------------------
11970 + 12345 = 24315
11970 + 23456 = 35426
11970 + 34567 = 46537
11970 + 45678 = 57648
11970 + 56789 = 68759
---------------------
12006 + 12345 = 24351
12006 + 23456 = 35462
12006 + 34567 = 46573
12006 + 45678 = 57684
12006 + 56789 = 68795
---------------------
12168 + 12345 = 24513
12168 + 23456 = 35624
12168 + 34567 = 46735
12168 + 45678 = 57846
12168 + 56789 = 68957
---------------------
12186 + 12345 = 24531
12186 + 23456 = 35642
12186 + 34567 = 46753
12186 + 45678 = 57864
12186 + 56789 = 68975
---------------------
12789 + 12345 = 25134
12789 + 23456 = 36245
12789 + 34567 = 47356
12789 + 45678 = 58467
12789 + 56789 = 69578
---------------------
12798 + 12345 = 25143
12798 + 23456 = 36254
12798 + 34567 = 47365
12798 + 45678 = 58476
12798 + 56789 = 69587
---------------------
12969 + 12345 = 25314
12969 + 23456 = 36425
12969 + 34567 = 47536
12969 + 45678 = 58647
12969 + 56789 = 69758
---------------------
12996 + 12345 = 25341
12996 + 23456 = 36452
12996 + 34567 = 47563
12996 + 45678 = 58674
12996 + 56789 = 69785
---------------------
13068 + 12345 = 25413
13068 + 23456 = 36524
13068 + 34567 = 47635
13068 + 45678 = 58746
13068 + 56789 = 69857
---------------------
13086 + 12345 = 25431
13086 + 23456 = 36542
13086 + 34567 = 47653
13086 + 45678 = 58764
13086 + 56789 = 69875
---------------------
18900 + 12345 = 31245
18900 + 23456 = 42356
18900 + 34567 = 53467
18900 + 45678 = 64578
18900 + 56789 = 75689
---------------------
18909 + 12345 = 31254
18909 + 23456 = 42365
18909 + 34567 = 53476
18909 + 45678 = 64587
18909 + 56789 = 75698
---------------------
19080 + 12345 = 31425
19080 + 23456 = 42536
19080 + 34567 = 53647
19080 + 45678 = 64758
19080 + 56789 = 75869
---------------------
19107 + 12345 = 31452
19107 + 23456 = 42563
19107 + 34567 = 53674
19107 + 45678 = 64785
19107 + 56789 = 75896
---------------------
19179 + 12345 = 31524
19179 + 23456 = 42635
19179 + 34567 = 53746
19179 + 45678 = 64857
19179 + 56789 = 75968
---------------------
19197 + 12345 = 31542
19197 + 23456 = 42653
19197 + 34567 = 53764
19197 + 45678 = 64875
19197 + 56789 = 75986
---------------------
19800 + 12345 = 32145
19800 + 23456 = 43256
19800 + 34567 = 54367
19800 + 45678 = 65478
19800 + 56789 = 76589
---------------------
19809 + 12345 = 32154
19809 + 23456 = 43265
19809 + 34567 = 54376
19809 + 45678 = 65487
19809 + 56789 = 76598
---------------------
20070 + 12345 = 32415
20070 + 23456 = 43526
20070 + 34567 = 54637
20070 + 45678 = 65748
20070 + 56789 = 76859
---------------------
20106 + 12345 = 32451
20106 + 23456 = 43562
20106 + 34567 = 54673
20106 + 45678 = 65784
20106 + 56789 = 76895
---------------------
20169 + 12345 = 32514
20169 + 23456 = 43625
20169 + 34567 = 54736
20169 + 45678 = 65847
20169 + 56789 = 76958
---------------------
20196 + 12345 = 32541
20196 + 23456 = 43652
20196 + 34567 = 54763
20196 + 45678 = 65874
20196 + 56789 = 76985
---------------------
21780 + 12345 = 34125
21780 + 23456 = 45236
21780 + 34567 = 56347
21780 + 45678 = 67458
21780 + 56789 = 78569
---------------------
21807 + 12345 = 34152
21807 + 23456 = 45263
21807 + 34567 = 56374
21807 + 45678 = 67485
21807 + 56789 = 78596
---------------------
21870 + 12345 = 34215
21870 + 23456 = 45326
21870 + 34567 = 56437
21870 + 45678 = 67548
21870 + 56789 = 78659
---------------------
21906 + 12345 = 34251
21906 + 23456 = 45362
21906 + 34567 = 56473
21906 + 45678 = 67584
21906 + 56789 = 78695
---------------------
22167 + 12345 = 34512
22167 + 23456 = 45623
22167 + 34567 = 56734
22167 + 45678 = 67845
22167 + 56789 = 78956
---------------------
22176 + 12345 = 34521
22176 + 23456 = 45632
22176 + 34567 = 56743
22176 + 45678 = 67854
22176 + 56789 = 78965
---------------------
22779 + 12345 = 35124
22779 + 23456 = 46235
22779 + 34567 = 57346
22779 + 45678 = 68457
22779 + 56789 = 79568
---------------------
22797 + 12345 = 35142
22797 + 23456 = 46253
22797 + 34567 = 57364
22797 + 45678 = 68475
22797 + 56789 = 79586
---------------------
22869 + 12345 = 35214
22869 + 23456 = 46325
22869 + 34567 = 57436
22869 + 45678 = 68547
22869 + 56789 = 79658
---------------------
22896 + 12345 = 35241
22896 + 23456 = 46352
22896 + 34567 = 57463
22896 + 45678 = 68574
22896 + 56789 = 79685
---------------------
23067 + 12345 = 35412
23067 + 23456 = 46523
23067 + 34567 = 57634
23067 + 45678 = 68745
23067 + 56789 = 79856
---------------------
23076 + 12345 = 35421
23076 + 23456 = 46532
23076 + 34567 = 57643
23076 + 45678 = 68754
23076 + 56789 = 79865
---------------------
28890 + 12345 = 41235
28890 + 23456 = 52346
28890 + 34567 = 63457
28890 + 45678 = 74568
28890 + 56789 = 85679
---------------------
28908 + 12345 = 41253
28908 + 23456 = 52364
28908 + 34567 = 63475
28908 + 45678 = 74586
28908 + 56789 = 85697
---------------------
28980 + 12345 = 41325
28980 + 23456 = 52436
28980 + 34567 = 63547
28980 + 45678 = 74658
28980 + 56789 = 85769
---------------------
29007 + 12345 = 41352
29007 + 23456 = 52463
29007 + 34567 = 63574
29007 + 45678 = 74685
29007 + 56789 = 85796
---------------------
29178 + 12345 = 41523
29178 + 23456 = 52634
29178 + 34567 = 63745
29178 + 45678 = 74856
29178 + 56789 = 85967
---------------------
29187 + 12345 = 41532
29187 + 23456 = 52643
29187 + 34567 = 63754
29187 + 45678 = 74865
29187 + 56789 = 85976
---------------------
29790 + 12345 = 42135
29790 + 23456 = 53246
29790 + 34567 = 64357
29790 + 45678 = 75468
29790 + 56789 = 86579
---------------------
29808 + 12345 = 42153
29808 + 23456 = 53264
29808 + 34567 = 64375
29808 + 45678 = 75486
29808 + 56789 = 86597
---------------------
29970 + 12345 = 42315
29970 + 23456 = 53426
29970 + 34567 = 64537
29970 + 45678 = 75648
29970 + 56789 = 86759
---------------------
30006 + 12345 = 42351
30006 + 23456 = 53462
30006 + 34567 = 64573
30006 + 45678 = 75684
30006 + 56789 = 86795
---------------------
30168 + 12345 = 42513
30168 + 23456 = 53624
30168 + 34567 = 64735
30168 + 45678 = 75846
30168 + 56789 = 86957
---------------------
30186 + 12345 = 42531
30186 + 23456 = 53642
30186 + 34567 = 64753
30186 + 45678 = 75864
30186 + 56789 = 86975
---------------------
30780 + 12345 = 43125
30780 + 23456 = 54236
30780 + 34567 = 65347
30780 + 45678 = 76458
30780 + 56789 = 87569
---------------------
30807 + 12345 = 43152
30807 + 23456 = 54263
30807 + 34567 = 65374
30807 + 45678 = 76485
30807 + 56789 = 87596
---------------------
30870 + 12345 = 43215
30870 + 23456 = 54326
30870 + 34567 = 65437
30870 + 45678 = 76548
30870 + 56789 = 87659
---------------------
30906 + 12345 = 43251
30906 + 23456 = 54362
30906 + 34567 = 65473
30906 + 45678 = 76584
30906 + 56789 = 87695
---------------------
31167 + 12345 = 43512
31167 + 23456 = 54623
31167 + 34567 = 65734
31167 + 45678 = 76845
31167 + 56789 = 87956
---------------------
31176 + 12345 = 43521
31176 + 23456 = 54632
31176 + 34567 = 65743
31176 + 45678 = 76854
31176 + 56789 = 87965
---------------------
32778 + 12345 = 45123
32778 + 23456 = 56234
32778 + 34567 = 67345
32778 + 45678 = 78456
32778 + 56789 = 89567
---------------------
32787 + 12345 = 45132
32787 + 23456 = 56243
32787 + 34567 = 67354
32787 + 45678 = 78465
32787 + 56789 = 89576
---------------------
32868 + 12345 = 45213
32868 + 23456 = 56324
32868 + 34567 = 67435
32868 + 45678 = 78546
32868 + 56789 = 89657
---------------------
32886 + 12345 = 45231
32886 + 23456 = 56342
32886 + 34567 = 67453
32886 + 45678 = 78564
32886 + 56789 = 89675
---------------------
32967 + 12345 = 45312
32967 + 23456 = 56423
32967 + 34567 = 67534
32967 + 45678 = 78645
32967 + 56789 = 89756
---------------------
32976 + 12345 = 45321
32976 + 23456 = 56432
32976 + 34567 = 67543
32976 + 45678 = 78654
32976 + 56789 = 89765
---------------------
38889 + 12345 = 51234
38889 + 23456 = 62345
38889 + 34567 = 73456
38889 + 45678 = 84567
38889 + 56789 = 95678
---------------------
38898 + 12345 = 51243
38898 + 23456 = 62354
38898 + 34567 = 73465
38898 + 45678 = 84576
38898 + 56789 = 95687
---------------------
38979 + 12345 = 51324
38979 + 23456 = 62435
38979 + 34567 = 73546
38979 + 45678 = 84657
38979 + 56789 = 95768
---------------------
38997 + 12345 = 51342
38997 + 23456 = 62453
38997 + 34567 = 73564
38997 + 45678 = 84675
38997 + 56789 = 95786
---------------------
39078 + 12345 = 51423
39078 + 23456 = 62534
39078 + 34567 = 73645
39078 + 45678 = 84756
39078 + 56789 = 95867
---------------------
39087 + 12345 = 51432
39087 + 23456 = 62543
39087 + 34567 = 73654
39087 + 45678 = 84765
39087 + 56789 = 95876
---------------------
39789 + 12345 = 52134
39789 + 23456 = 63245
39789 + 34567 = 74356
39789 + 45678 = 85467
39789 + 56789 = 96578
---------------------
39798 + 12345 = 52143
39798 + 23456 = 63254
39798 + 34567 = 74365
39798 + 45678 = 85476
39798 + 56789 = 96587
---------------------
39969 + 12345 = 52314
39969 + 23456 = 63425
39969 + 34567 = 74536
39969 + 45678 = 85647
39969 + 56789 = 96758
---------------------
39996 + 12345 = 52341
39996 + 23456 = 63452
39996 + 34567 = 74563
39996 + 45678 = 85674
39996 + 56789 = 96785
---------------------
40068 + 12345 = 52413
40068 + 23456 = 63524
40068 + 34567 = 74635
40068 + 45678 = 85746
40068 + 56789 = 96857
---------------------
40086 + 12345 = 52431
40086 + 23456 = 63542
40086 + 34567 = 74653
40086 + 45678 = 85764
40086 + 56789 = 96875
---------------------
40779 + 12345 = 53124
40779 + 23456 = 64235
40779 + 34567 = 75346
40779 + 45678 = 86457
40779 + 56789 = 97568
---------------------
40797 + 12345 = 53142
40797 + 23456 = 64253
40797 + 34567 = 75364
40797 + 45678 = 86475
40797 + 56789 = 97586
---------------------
40869 + 12345 = 53214
40869 + 23456 = 64325
40869 + 34567 = 75436
40869 + 45678 = 86547
40869 + 56789 = 97658
---------------------
40896 + 12345 = 53241
40896 + 23456 = 64352
40896 + 34567 = 75463
40896 + 45678 = 86574
40896 + 56789 = 97685
---------------------
41067 + 12345 = 53412
41067 + 23456 = 64523
41067 + 34567 = 75634
41067 + 45678 = 86745
41067 + 56789 = 97856
---------------------
41076 + 12345 = 53421
41076 + 23456 = 64532
41076 + 34567 = 75643
41076 + 45678 = 86754
41076 + 56789 = 97865
---------------------
41778 + 12345 = 54123
41778 + 23456 = 65234
41778 + 34567 = 76345
41778 + 45678 = 87456
41778 + 56789 = 98567
---------------------
41787 + 12345 = 54132
41787 + 23456 = 65243
41787 + 34567 = 76354
41787 + 45678 = 87465
41787 + 56789 = 98576
---------------------
41868 + 12345 = 54213
41868 + 23456 = 65324
41868 + 34567 = 76435
41868 + 45678 = 87546
41868 + 56789 = 98657
---------------------
41886 + 12345 = 54231
41886 + 23456 = 65342
41886 + 34567 = 76453
41886 + 45678 = 87564
41886 + 56789 = 98675
---------------------
41967 + 12345 = 54312
41967 + 23456 = 65423
41967 + 34567 = 76534
41967 + 45678 = 87645
41967 + 56789 = 98756
---------------------
41976 + 12345 = 54321
41976 + 23456 = 65432
41976 + 34567 = 76543
41976 + 45678 = 87654
41976 + 56789 = 98765
---------------------
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。