var xo = [String]()
var xo1 = ["x" , "10" ,"10" ,"10","10" ]
var xo2 = ["10 " , "x" ,"10" ,"10" ,"10" ]
var xo3 = ["10 " , "10" ,"x" ,"10" ,"10" ]
var xo4 = ["10 " , "10" ,"10" ,"x" ,"10"]
var xo5 = ["10 " , "10" ,"10" ,"10" ,"x" ]
xo.append(contentsOf: xo1)
xo.append(contentsOf: xo2)
xo.append(contentsOf: xo3)
xo.append(contentsOf: xo4)
xo.append(contentsOf: xo5)
//for _ in xo {
// print(xo)
//}
func xos (item: Int , count:Int ) -> [String] {
let xo8 = Array(repeating: item, count: count)
let xo9 = Array(repeating: item, count: count)
}
xos(item: xo, count: 1)
whats wrong ? how i can print like this :
[X, 0, 0, 0, 0]
[0, X, 0, 0, 0]
[0, 0, X, 0, 0]
[0, 0, 0, X, 0]
[0, 0, 0, 0, X]
var xo1 = ["x" , "10" ,"10" ,"10","10" ]
var xo2 = ["10 " , "x" ,"10" ,"10" ,"10" ]
var xo3 = ["10 " , "10" ,"x" ,"10" ,"10" ]
var xo4 = ["10 " , "10" ,"10" ,"x" ,"10"]
var xo5 = ["10 " , "10" ,"10" ,"10" ,"x" ]
xo.append(contentsOf: xo1)
xo.append(contentsOf: xo2)
xo.append(contentsOf: xo3)
xo.append(contentsOf: xo4)
xo.append(contentsOf: xo5)
//for _ in xo {
// print(xo)
//}
func xos (item: Int , count:Int ) -> [String] {
let xo8 = Array(repeating: item, count: count)
let xo9 = Array(repeating: item, count: count)
}
xos(item: xo, count: 1)
whats wrong ? how i can print like this :
[X, 0, 0, 0, 0]
[0, X, 0, 0, 0]
[0, 0, X, 0, 0]
[0, 0, 0, X, 0]
[0, 0, 0, 0, X]
Your answers are absolutely confusing.
If you want a matrix in x0, declare
and populate as follows:
Then with
[["x", "10", "10", "10", "10"], ["10 ", "x", "10", "10", "10"], ["10 ", "10", "x", "10", "10"], ["10 ", "10", "10", "x", "10"], ["10 ", "10", "10", "10", "x"]]
Or with:
["x", "10", "10", "10", "10"]
["10 ", "x", "10", "10", "10"]
["10 ", "10", "x", "10", "10"]
["10 ", "10", "10", "x", "10"]
["10 ", "10", "10", "10", "x"]
Is it what you are looking for ?
If so, don't forget to close the thread on this answer.
Otherwise, please explain what different output you want.
If you want a matrix in x0, declare
Code Block var matrix = [[String]]() // Array of Arrays ; changed the name to be more meaningful
and populate as follows:
Code Block var xo1 = ["x", "10","10","10","10"] var xo2 = ["10 ","x", "10","10","10"] var xo3 = ["10 ","10","x" ,"10","10"] var xo4 = ["10 ","10","10","x" ,"10"] var xo5 = ["10 ","10","10","10","x"] matrix.append(xo1) matrix.append(xo2) matrix.append(xo3) matrix.append(xo4) matrix.append(xo5)
Then with
Code Block print(matrix)
you get[["x", "10", "10", "10", "10"], ["10 ", "x", "10", "10", "10"], ["10 ", "10", "x", "10", "10"], ["10 ", "10", "10", "x", "10"], ["10 ", "10", "10", "10", "x"]]
Or with:
Code Block for row in matrix { print(row) }
you get["x", "10", "10", "10", "10"]
["10 ", "x", "10", "10", "10"]
["10 ", "10", "x", "10", "10"]
["10 ", "10", "10", "x", "10"]
["10 ", "10", "10", "10", "x"]
Is it what you are looking for ?
If so, don't forget to close the thread on this answer.
Otherwise, please explain what different output you want.