回答編集履歴

2

修正

2018/10/18 05:27

投稿

退会済みユーザー
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  (1..10).each do |x|
34
34
 
35
- next if 7/x != 0 || 7.divmod(x)[1] == 0
35
+ next if 7/x == 0 || 7.divmod(x)[1] == 0
36
36
 
37
37
  hash[x] = 7.divmod(x)
38
38
 

1

rubyっぽく書いた

2018/10/18 05:26

投稿

退会済みユーザー
test CHANGED
@@ -28,6 +28,22 @@
28
28
 
29
29
 
30
30
 
31
+ # rubyっぽく書くなら -----
32
+
33
+ (1..10).each do |x|
34
+
35
+ next if 7/x != 0 || 7.divmod(x)[1] == 0
36
+
37
+ hash[x] = 7.divmod(x)
38
+
39
+ end
40
+
41
+ end
42
+
43
+ # --------------------
44
+
45
+
46
+
31
47
  hash
32
48
 
33
49
  #=> {2=>[3, 1], 3=>[2, 1], 4=>[1, 3], 5=>[1, 2], 6=>[1, 1]}