1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 19:19:07 +01:00
CodeWars/6kyu/give_me_a_diamond/solution.swift

24 lines
405 B
Swift
Raw Normal View History

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
}