Last active
April 16, 2018 12:52
-
-
Save jbarros35/8c41f1a147dcc715e9c0b6926be4f60b to your computer and use it in GitHub Desktop.
Swift code printing X in the screen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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