回答編集履歴

5

修正

2017/03/15 16:36

投稿

退会済みユーザー
test CHANGED
@@ -17,8 +17,6 @@
17
17
  return "『#{comp.count(2)}文字違い、#{answer}が不一致です』"
18
18
 
19
19
  end
20
-
21
-
22
20
 
23
21
 
24
22
 

4

修正

2017/03/15 16:36

投稿

退会済みユーザー
test CHANGED
@@ -1,30 +1,6 @@
1
1
  ```Ruby
2
2
 
3
3
  #encoding : utf-8
4
-
5
-
6
-
7
- def check(word1, word2)
8
-
9
- if word1 == word2
10
-
11
- puts "完全に一致です。"
12
-
13
- else
14
-
15
- if word1.size != word2.size
16
-
17
- puts "文字数が不一致です。"
18
-
19
- else
20
-
21
- word_test(word1, word2)
22
-
23
- end
24
-
25
- end
26
-
27
- end
28
4
 
29
5
 
30
6
 
@@ -38,13 +14,33 @@
38
14
 
39
15
  answer = answer.join(",").gsub(",", "、")
40
16
 
41
- puts "『#{comp.count(2)}文字違い、#{answer}が不一致です』"
17
+ return "『#{comp.count(2)}文字違い、#{answer}が不一致です』"
42
18
 
43
19
  end
44
20
 
45
21
 
46
22
 
23
+
24
+
47
- check(ARGV[0], ARGV[1])
25
+ word1, word2 = ARGV[0], ARGV[1]
26
+
27
+ if word1 == word2
28
+
29
+ puts "完全に一致です。"
30
+
31
+ else
32
+
33
+ if word1.size != word2.size
34
+
35
+ puts "文字数が不一致です。"
36
+
37
+ else
38
+
39
+ puts word_test(word1, word2)
40
+
41
+ end
42
+
43
+ end
48
44
 
49
45
  ```
50
46
 

3

修正

2017/03/15 16:35

投稿

退会済みユーザー
test CHANGED
@@ -34,11 +34,11 @@
34
34
 
35
35
  comp = comp.map{|e| e.uniq.size}
36
36
 
37
- print "#{comp.count(2)}文字違い、"
37
+ answer = comp.map.with_index{|e, i| "#{i + 1}番目" if e == 2}.compact
38
38
 
39
- comp.map!.with_index{|e, i| "#{i + 1}番目" if e == 2}.compact!
39
+ answer = answer.join(",").gsub(",", "、")
40
40
 
41
- puts "#{comp.join(",").gsub(",", "、")}が不一致です』"
41
+ puts "#{comp.count(2)}文字違い、#{answer}が不一致です』"
42
42
 
43
43
  end
44
44
 

2

修正

2017/03/15 16:25

投稿

退会済みユーザー
test CHANGED
@@ -1,38 +1,24 @@
1
1
  ```Ruby
2
2
 
3
- def word_test(word1, word2)
3
+ #encoding : utf-8
4
4
 
5
- word1 = word1.split("")
6
5
 
7
- word2 = word2.split("")
8
6
 
9
- if word1.length != word2.length
7
+ def check(word1, word2)
10
8
 
9
+ if word1 == word2
10
+
11
- print "文字数が不一致です。"
11
+ puts "完全に一致です。"
12
12
 
13
13
  else
14
14
 
15
- word1.map!.with_index{|e, i| e != word2[i] ? [e, word2[i]] : [e] }
15
+ if word1.size != word2.size
16
16
 
17
- answer = []
18
-
19
- word1.length.times do |x|
20
-
21
- element = word1[x]
22
-
23
- answer << x if element.length != 1
24
-
25
- end
26
-
27
- unless answer.none?
28
-
29
- print "#{answer.length}文字違い\s"
17
+ puts "文字数が不一致です。"
30
-
31
- answer.each{|e| print (e + 1).to_s + "番目\s"}
32
18
 
33
19
  else
34
20
 
35
- print "完全に一致です。"
21
+ word_test(word1, word2)
36
22
 
37
23
  end
38
24
 
@@ -42,7 +28,23 @@
42
28
 
43
29
 
44
30
 
31
+ def word_test(word1, word2)
32
+
33
+ comp = word1.split("").zip(word2.split(""))
34
+
35
+ comp = comp.map{|e| e.uniq.size}
36
+
37
+ print "『#{comp.count(2)}文字違い、"
38
+
39
+ comp.map!.with_index{|e, i| "#{i + 1}番目" if e == 2}.compact!
40
+
41
+ puts "#{comp.join(",").gsub(",", "、")}が不一致です』"
42
+
43
+ end
44
+
45
+
46
+
45
- word_test(ARGV[0], ARGV[1])
47
+ check(ARGV[0], ARGV[1])
46
48
 
47
49
  ```
48
50
 

1

修正

2017/03/15 16:21

投稿

退会済みユーザー
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  answer = []
18
18
 
19
- (word1.length).times do |x|
19
+ word1.length.times do |x|
20
20
 
21
21
  element = word1[x]
22
22