Skip to content

Instantly share code, notes, and snippets.

View vitorventurin's full-sized avatar
🏠
Working from home

Vitor Venturin vitorventurin

🏠
Working from home
View GitHub Profile
@vitorventurin
vitorventurin / Favorite_Extensions_Swift
Created February 23, 2021 09:33
My favorite extensions from Swift Language / iOS Cocoa UIKit
// The version of Swift is 4.0.
// Get a class name
public protocol ClassNameProtocol {
static var className: String { get }
var className: String { get }
}
public extension ClassNameProtocol {
public static var className: String {
@vitorventurin
vitorventurin / RomanNumbers.playground
Created February 23, 2021 09:39
Legionaries: In the range 1-13 (1,2,3,4,5,6,7,8,9,10,11,12,13) the digit 1 occurs 6 times. In the range, 1 - 2,660 (half the number of Romans in a legion), expressed in Roman numerals, how many times does the numeral “X” occur?
import Foundation
func toRoman(number: Int) -> String {
let romanValues = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
let arabicValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
var romanValue = ""
var startingValue = number
for (index, romanChar) in romanValues.enumerated() {
@vitorventurin
vitorventurin / Hackerrank_RepeatedString.playground
Created March 2, 2021 10:28
Hackerrank - Repeated String
import Foundation
func getLetterCount(s: String) -> Int {
return s.filter { $0 == "a" }.count
}
func repeatedString(s: String, n: Int) -> Int {
let stringCount = s.count
let remainder = n % stringCount
let multiplier = n / stringCount