Created
February 20, 2022 05:06
-
-
Save KunalKumarSwift/ce593cc689b8a700cfe79ed6e67c92ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var n = 8 | |
var row = 2 * n - 1 | |
for i in 1...n { | |
for j in 1...row { | |
let lowerRange = n-(i-1) | |
let upperRange = n+(i-1) | |
if j < lowerRange { | |
print(" ", terminator: " ") | |
} | |
if (lowerRange..<n).contains(j) { | |
print(((i) - (n-j)), terminator: " ") | |
} | |
if j == n { | |
print(i, terminator: " ") | |
} | |
if (n+1..<upperRange+1).contains(j) { | |
print((i) - (j - n), terminator: " ") | |
} | |
} | |
print("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment