From 98d190cd655d219379f70a6047c80a148c36ccbb Mon Sep 17 00:00:00 2001 From: franmu94 Date: Wed, 9 Nov 2022 02:07:42 +0100 Subject: [PATCH] =?UTF-8?q?Soluci=C3=B3n=20Reto=20#[45]=20[SWIFT]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contents.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/WeeklyChallenge2022.playground/Pages/Challenge45.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge45.xcplaygroundpage/Contents.swift index f340f95..9d3c3f9 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge45.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge45.xcplaygroundpage/Contents.swift @@ -29,3 +29,26 @@ import Foundation * https://retosdeprogramacion.com/semanales2022. * */ + + + + + func countWatter(lista: [Int]) -> Int{ + var cont = 0 + for (inx,i) in lista.enumerated(){ + if inx == lista.count - 1 || inx == 0 {continue} + let m = [lista[0.. i{ + cont += m - i + } + + } + + return cont + } + +countWatter(lista: [4, 0, 3, 6, 1, 3]) + +countWatter(lista: [4, 0, 3, 6, 1, 3].reversed()) + +countWatter(lista: [4, 0, 3, 6, 1, 3].sorted())