Swift 4.2 でのストライド機能の使用
12345
2345
345
45
5
5
45
345
2345
12345
for i in 1...5{
for k in 1...i{
print(terminator : " ")
}
for j in stride(from: i, to: 6, by: 1){
print(j , terminator : "")
}
print(" ")
}
for i in stride(from: 5, to: 0, by: -1)
{
for k in 1...i{
print(terminator : " ")
}
for j in stride(from: i, to: 6, by: 1){
print(j,terminator : "")
}
print(" ")
}
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
for i in 1...5{
for k in 0...i{
print(terminator : " ")
}
for j in stride(from: i, to: 6, by: 1){
print(j , terminator : " ")
}
print(" ")
}
for i in stride(from: 6, to: 1, by: -1){
for k in 1...i{
print(terminator : " ")
}
for j in stride(from: i-1, to: 6, by: 1){
print(j , terminator : " ")
}
print(" ")
}