1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/6kyu/give_me_a_diamond/solution.swift
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

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
}