2017年11月6日月曜日

171106

Ruby


8765432 * 8 = 70123456

数遊びをしてみる。

def show(ary, k, n)
  ary.each{|i| puts "#{i} * #{k} = #{i * k}"}
end

n = 20
ary = (0..n).map{|i| ((9 * i + 8) * 10 ** i - 8) / 81}
show(ary, 8, n)
show(ary, 9, n)
ary = (0..n).map{|i| ((-9 * i + 82) * 10 ** i - 1) / 81}
show(ary, 8, n)
show(ary, 9, n)

出力結果
0 * 8 = 0
2 * 8 = 16
32 * 8 = 256
432 * 8 = 3456
5432 * 8 = 43456
65432 * 8 = 523456
765432 * 8 = 6123456
8765432 * 8 = 70123456
98765432 * 8 = 790123456
1098765432 * 8 = 8790123456
12098765432 * 8 = 96790123456
132098765432 * 8 = 1056790123456
1432098765432 * 8 = 11456790123456
15432098765432 * 8 = 123456790123456
165432098765432 * 8 = 1323456790123456
1765432098765432 * 8 = 14123456790123456
18765432098765432 * 8 = 150123456790123456
198765432098765432 * 8 = 1590123456790123456
2098765432098765432 * 8 = 16790123456790123456
22098765432098765432 * 8 = 176790123456790123456
232098765432098765432 * 8 = 1856790123456790123456
0 * 9 = 0
2 * 9 = 18
32 * 9 = 288
432 * 9 = 3888
5432 * 9 = 48888
65432 * 9 = 588888
765432 * 9 = 6888888
8765432 * 9 = 78888888
98765432 * 9 = 888888888
1098765432 * 9 = 9888888888
12098765432 * 9 = 108888888888
132098765432 * 9 = 1188888888888
1432098765432 * 9 = 12888888888888
15432098765432 * 9 = 138888888888888
165432098765432 * 9 = 1488888888888888
1765432098765432 * 9 = 15888888888888888
18765432098765432 * 9 = 168888888888888888
198765432098765432 * 9 = 1788888888888888888
2098765432098765432 * 9 = 18888888888888888888
22098765432098765432 * 9 = 198888888888888888888
232098765432098765432 * 9 = 2088888888888888888888
1 * 8 = 8
9 * 8 = 72
79 * 8 = 632
679 * 8 = 5432
5679 * 8 = 45432
45679 * 8 = 365432
345679 * 8 = 2765432
2345679 * 8 = 18765432
12345679 * 8 = 98765432
12345679 * 8 = 98765432
-987654321 * 8 = -7901234568
-20987654321 * 8 = -167901234568
-320987654321 * 8 = -2567901234568
-4320987654321 * 8 = -34567901234568
-54320987654321 * 8 = -434567901234568
-654320987654321 * 8 = -5234567901234568
-7654320987654321 * 8 = -61234567901234568
-87654320987654321 * 8 = -701234567901234568
-987654320987654321 * 8 = -7901234567901234568
-10987654320987654321 * 8 = -87901234567901234568
-120987654320987654321 * 8 = -967901234567901234568
1 * 9 = 9
9 * 9 = 81
79 * 9 = 711
679 * 9 = 6111
5679 * 9 = 51111
45679 * 9 = 411111
345679 * 9 = 3111111
2345679 * 9 = 21111111
12345679 * 9 = 111111111
12345679 * 9 = 111111111
-987654321 * 9 = -8888888889
-20987654321 * 9 = -188888888889
-320987654321 * 9 = -2888888888889
-4320987654321 * 9 = -38888888888889
-54320987654321 * 9 = -488888888888889
-654320987654321 * 9 = -5888888888888889
-7654320987654321 * 9 = -68888888888888889
-87654320987654321 * 9 = -788888888888888889
-987654320987654321 * 9 = -8888888888888888889
-10987654320987654321 * 9 = -98888888888888888889
-120987654320987654321 * 9 = -1088888888888888888889

0 件のコメント:

コメントを投稿