Skip to content

Instantly share code, notes, and snippets.

@jbarros35
Last active April 16, 2018 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarros35/8c41f1a147dcc715e9c0b6926be4f60b to your computer and use it in GitHub Desktop.
Save jbarros35/8c41f1a147dcc715e9c0b6926be4f60b to your computer and use it in GitHub Desktop.
Swift code printing X in the screen.
let matrixSize = 10
for y in 0..<matrixSize {
var line = ""
for x in 0..<matrixSize {
let point = (x, y)
switch point {
case let (x, y) where x == y:
line.append("#")
case let (x, y) where y == matrixSize-1 || y == 0 || x == 0 || x == matrixSize-1:
line.append("#")
case let (x, y) where x + y == matrixSize-1:
line.append("#")
default: line.append(" ")
}
}
print(line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment