# ThirdDay

## 3. 配列

### 例題：配列(list.rb)

[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% ruby ex3-1.rb
5
4
3
2
1
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex3-1.rb
a=[5,4,3,2,1]
for i in 0..4 do
puts a[i]
end
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex3-1r.rb
a=[5,4,3,2,1]
a.each do |tmp|
puts tmp
end

### 例題：1から100までの乱数を１０個格納した配列を作れ．(rand.rb)

ruby ex3-2.rb
[9, 13, 5, 51, 15, 51, 5, 99, 77, 88]
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex3-2.rb
a=[]
10.times do
tmp=rand(100)+1
puts tmp
a << tmp
end
p a

### 課題：さいころを１００回振って，1から6の目が何回出たかを表示せよ(dice.rb)

[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% !r
ruby ex3-3.rb
[0, 21, 15, 17, 15, 13, 19]

### 例題：rand()で生成される小数の１０桁目までを配列に蓄えよ．(rand2list.rb))

[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% !r
ruby ex3-4.rb
0.975006684566814
[9, 7, 5, 0, 0, 6, 6, 8, 4, 5]
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex3-4.rb
a=rand()
puts a
num=[]
10.times do
b=(a*10).to_i
puts b
a=a*10-b
num << b
end
p num

### 課題：前問で求めた配列から１０桁の整数を作れ．(list2int.rb)

[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% ruby ex3-5.rb
0.258949661837373
[2, 5, 8, 9, 4, 9, 6, 6, 1, 8]
2589496618