Skip to content

Instantly share code, notes, and snippets.

@KunalKumarSwift
Created February 20, 2022 05:06
Show Gist options
  • Save KunalKumarSwift/ce593cc689b8a700cfe79ed6e67c92ca to your computer and use it in GitHub Desktop.
Save KunalKumarSwift/ce593cc689b8a700cfe79ed6e67c92ca to your computer and use it in GitHub Desktop.
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