Advertisement
greedydev

Untitled

Jun 1st, 2024
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.32 KB | None | 0 0
  1. import Foundation
  2.  
  3. func drawSquare(_ n: Int) {
  4.     let size = 2 * n + 1
  5.    
  6.     for i in 0..<size {
  7.         for j in 0..<size {
  8.             let distance = max(abs(n - i), abs(n - j))
  9.             let number = 9 - distance
  10.             print(number, terminator: "")
  11.         }
  12.         print()
  13.     }
  14. }
  15.  
  16.  
  17. let input = 3
  18. drawSquare(input)
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement