回答編集履歴
2
改行前にカンマを追加
answer
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
let a = [0, 2, 3, 1, 2, 3, 2, 5, 26, 23]
|
14
14
|
|
15
15
|
zip(a, ThreeCount()).forEach {
|
16
|
-
print($0.0, terminator: $0.1 ? "\n" : ",")
|
16
|
+
print($0.0, terminator: $0.1 ? ",\n" : ",")
|
17
17
|
}
|
18
18
|
print("")
|
19
19
|
```
|
1
SequenceのElementをBoolにすることで無駄な処理をなくした
answer
CHANGED
@@ -3,20 +3,17 @@
|
|
3
3
|
```swift
|
4
4
|
struct ThreeCount: Sequence, IteratorProtocol {
|
5
5
|
var current = 0
|
6
|
-
mutating func next() ->
|
6
|
+
mutating func next() -> Bool? {
|
7
7
|
let res = current
|
8
8
|
current = (current + 1) % 3
|
9
|
-
return res
|
9
|
+
return res == 2
|
10
10
|
}
|
11
11
|
}
|
12
12
|
|
13
|
-
func isThree(_ val: Int) -> Bool { return val == 3 }
|
14
|
-
|
15
|
-
|
16
13
|
let a = [0, 2, 3, 1, 2, 3, 2, 5, 26, 23]
|
17
14
|
|
18
15
|
zip(a, ThreeCount()).forEach {
|
19
|
-
print($0.0, terminator:
|
16
|
+
print($0.0, terminator: $0.1 ? "\n" : ",")
|
20
17
|
}
|
21
18
|
print("")
|
22
19
|
```
|