mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 11:09:07 +01:00
23 lines
405 B
Swift
23 lines
405 B
Swift
func diamond(_ size: Int) -> String? {
|
|
if size < 0 || size % 2 == 0 {
|
|
return nil
|
|
}
|
|
|
|
var result = ""
|
|
var (count, diff) = (1, 2)
|
|
|
|
while count > 0 {
|
|
print(count, diff)
|
|
result += String(repeating: " ", count: (size - count) / 2)
|
|
result += String(repeating: "*", count: count)
|
|
result += "\n"
|
|
|
|
if count == size {
|
|
diff = -2
|
|
}
|
|
|
|
count += diff
|
|
}
|
|
|
|
return result
|
|
}
|