From 224b29b88a95e6134e72ebdf8b152d92e21b4b0e Mon Sep 17 00:00:00 2001 From: franmu94 Date: Sun, 4 Feb 2024 00:29:18 +0100 Subject: [PATCH] Reto 16 Swift --- .../swift/franmu94.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Retos/Reto #16 - LA ESCALERA [Media]/swift/franmu94.swift diff --git a/Retos/Reto #16 - LA ESCALERA [Media]/swift/franmu94.swift b/Retos/Reto #16 - LA ESCALERA [Media]/swift/franmu94.swift new file mode 100644 index 0000000000..f51eccaab7 --- /dev/null +++ b/Retos/Reto #16 - LA ESCALERA [Media]/swift/franmu94.swift @@ -0,0 +1,30 @@ +import Foundation + +func escalera(escalones e: Int) { + if e == 0 { + print("__") + return + } + let n = abs(e) + let c = e > 0 ? "_|" : "|_" + var arr = [String]() + var espacios = "" + for i in (0...n){ + if i == n && e > 0 { + arr.append(espacios + "_") + } else if i == 0 && e < 0 { + arr.append(espacios + "_") + espacios += " " + } else { + arr.append(espacios + c) + espacios += " " + } + } + + e > 0 ? arr.reversed().forEach{ print($0) } : arr.forEach{ print($0) } +} +escalera(escalones: -4) +escalera(escalones: 9) +escalera(escalones: 0) + +