回答編集履歴

6

typo

2020/03/23 12:06

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  val midChars = text.toList().drop(1).dropLast(1)
26
26
 
27
- val midLInes =
27
+ val midLines =
28
28
 
29
29
  midChars.zip(midChars.reversed())
30
30
 
@@ -32,7 +32,7 @@
32
32
 
33
33
  //
34
34
 
35
- return listOf(text) + midLInes + listOf(text.reversed())
35
+ return listOf(text) + midLines + listOf(text.reversed())
36
36
 
37
37
  }
38
38
 

5

内容修正

2020/03/23 12:06

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -1,54 +1,50 @@
1
1
  String#format()とzip()とreversed()で実装してみた。
2
+
3
+
4
+
5
+ けれど、Paalonさんの回答とおりにはなるけれど、「実現したいこと」は中間の行のあいだに挟まる空白の数がランダムらしいので、テストは通せなかった。`n`のうしろに空白があったりもするし。わたしが仕様をただしく読み取れていない可能性大。
2
6
 
3
7
 
4
8
 
5
9
  ```kotlin
6
10
 
7
- object xxOogiri {
11
+ import org.junit.Assert
8
12
 
9
- @JvmStatic
13
+ import org.junit.Test
10
14
 
11
- fun main(args: Array<String>) {
12
15
 
13
- val text = "tabemono"
14
16
 
15
- // 編集書式
17
+ class xxOogiri {
16
18
 
17
- val format = "%s%${text.length - 1}s"
19
+ //
18
20
 
19
- // 中間文字のリスト
21
+ private fun mkBox(text: String): List<String> {
20
22
 
21
- val charList = text.toList().drop(1).dropLast(1)
23
+ val fmt = "%s%${text.length - 1}s" // 編集書式
22
24
 
23
- // 中間文字のリストと中間文字のリストの逆転をzipして、編集する
25
+ val midChars = text.toList().drop(1).dropLast(1)
24
26
 
25
- val list =
27
+ val midLInes =
26
28
 
27
- charList.zip(charList.reversed())
29
+ midChars.zip(midChars.reversed())
28
30
 
29
- .map { (a, b) -> format.format(a, b) }
31
+ .map { (a, b) -> fmt.format(a, b) }
30
32
 
31
33
  //
32
34
 
33
- println(text)
34
-
35
- println(list.joinToString("\n"))
36
-
37
- println(text.reversed())
35
+ return listOf(text) + midLInes + listOf(text.reversed())
38
36
 
39
37
  }
40
38
 
41
- }
42
-
43
- ```
44
39
 
45
40
 
41
+ @Test
46
42
 
47
- 実行結果
43
+ fun 想像した結果のテスト_Paalonさんの回答() {
48
44
 
45
+ //
49
46
 
50
-
51
- ```text
47
+ val expect = """
52
48
 
53
49
  tabemono
54
50
 
@@ -66,4 +62,60 @@
66
62
 
67
63
  onomebat
68
64
 
65
+ """.trimIndent()
66
+
67
+
68
+
69
+ val actual = mkBox("tabemono").joinToString("\n")
70
+
71
+ println(actual)
72
+
73
+
74
+
75
+ Assert.assertEquals(expect, actual)
76
+
77
+ }
78
+
79
+
80
+
81
+ @Test
82
+
83
+ fun 実現したいこと_のテスト() {
84
+
85
+ //
86
+
87
+ val expect = """
88
+
89
+ tabemono
90
+
91
+ a   n
92
+
93
+ b  o
94
+
95
+ e   m
96
+
97
+ m e
98
+
99
+ o b
100
+
101
+ n a
102
+
103
+ onomebat
104
+
105
+ """.trimIndent()
106
+
107
+
108
+
109
+ val actual = mkBox("tabemono").joinToString("\n")
110
+
111
+ println(actual)
112
+
113
+
114
+
115
+ Assert.assertEquals(expect, actual)
116
+
117
+ }
118
+
119
+ }
120
+
69
121
  ```

4

サンプルを修正した

2020/03/22 21:45

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -12,11 +12,9 @@
12
12
 
13
13
  val text = "tabemono"
14
14
 
15
-
16
-
17
15
  // 編集書式
18
16
 
19
- val format = "%s%${text.length - 2}s%s"
17
+ val format = "%s%${text.length - 1}s"
20
18
 
21
19
  // 中間文字のリスト
22
20
 
@@ -28,7 +26,7 @@
28
26
 
29
27
  charList.zip(charList.reversed())
30
28
 
31
- .map { (a, b) -> format.format(a, "", b) }
29
+ .map { (a, b) -> format.format(a, b) }
32
30
 
33
31
  //
34
32
 

3

サンプルを修正した

2020/03/22 13:25

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -18,11 +18,11 @@
18
18
 
19
19
  val format = "%s%${text.length - 2}s%s"
20
20
 
21
- // 最初と最後を取り除いた文字のリストをつくる
21
+ // 中間文字のリスト
22
22
 
23
23
  val charList = text.toList().drop(1).dropLast(1)
24
24
 
25
- // 文字のリストと文字のリストの逆転をzipして、編集する
25
+ // 中間文字のリストと中間文字のリストの逆転をzipして、編集する
26
26
 
27
27
  val list =
28
28
 

2

typo

2020/03/22 12:10

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -1,4 +1,4 @@
1
- String#format()とzip()とreverse()で実装してみた。
1
+ String#format()とzip()とreversed()で実装してみた。
2
2
 
3
3
 
4
4
 

1

typo

2020/03/22 12:05

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -1,3 +1,7 @@
1
+ String#format()とzip()とreverse()で実装してみた。
2
+
3
+
4
+
1
5
  ```kotlin
2
6
 
3
7
  object xxOogiri {
@@ -6,17 +10,19 @@
6
10
 
7
11
  fun main(args: Array<String>) {
8
12
 
9
- val tabemono = "tabemono"
13
+ val text = "tabemono"
14
+
15
+
10
16
 
11
17
  // 編集書式
12
18
 
13
- val format = "%s%${tabemono.length - 2}s%s"
19
+ val format = "%s%${text.length - 2}s%s"
14
20
 
15
- // 中間文字のリスト
21
+ // 最初と最後を取り除いた文字のリストをつくる
16
22
 
17
- val charList = tabemono.toList().drop(1).dropLast(1)
23
+ val charList = text.toList().drop(1).dropLast(1)
18
24
 
19
- // 中間文字のリストと中間文字のリストの逆転をzipして、編集する
25
+ // 文字のリストと文字のリストの逆転をzipして、編集する
20
26
 
21
27
  val list =
22
28
 
@@ -26,11 +32,11 @@
26
32
 
27
33
  //
28
34
 
29
- println(tabemono)
35
+ println(text)
30
36
 
31
37
  println(list.joinToString("\n"))
32
38
 
33
- println(tabemono.reversed())
39
+ println(text.reversed())
34
40
 
35
41
  }
36
42