From 9eeca382c7df2c187c95827efd2d73c47eb76094 Mon Sep 17 00:00:00 2001 From: gabarr Date: Sun, 31 Jul 2022 22:14:24 +0200 Subject: [PATCH] =?UTF-8?q?Resoluci=C3=B3n=20Reto=20#30=20en=20Ruby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contents.swift | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift b/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift index f7655da..5ec8433 100644 --- a/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift +++ b/WeeklyChallenge2022.playground/Pages/Challenge30.xcplaygroundpage/Contents.swift @@ -1,4 +1,6 @@ -import Foundation +#!/usr/bin/env ruby + +#import Foundation /* * Reto #30 @@ -25,3 +27,28 @@ import Foundation * - Subiré una posible solución al ejercicio el lunes siguiente al de su publicación. * */ + + +def word_frame (sentence) + max_len = 0 + words = sentence.split + words.each do |word| + if word.length > max_len + max_len = word.length + end + end + + # top line + puts "*" * (max_len + 4) + + # core lines + words.each do |word| + puts "* " + word + " " * (max_len - word.length) + " *" + end + + # bottom line + puts "*" * (max_len + 4) + +end + +word_frame "Dos cosas son infinitas: la estupidez humana y el universo. Y de lo segundo ¡no estoy seguro!" \ No newline at end of file