Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Vitor Venturin vitorventurin

🏠
Working from home
View GitHub Profile
View Hackerrank_RepeatedString.playground
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
@vitorventurin
vitorventurin / RomanNumbers.playground
Created Feb 23, 2021
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?
View RomanNumbers.playground
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 / Favorite_Extensions_Swift
Created Feb 23, 2021
My favorite extensions from Swift Language / iOS Cocoa UIKit
View Favorite_Extensions_Swift
// 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 {
View objc_setAssociatedObject.playground
import UIKit
protocol PropertyStoring {
associatedtype T
func getAssociatedObject(_ key: UnsafeRawPointer, defaultValue: T) -> T
}
extension PropertyStoring {
func getAssociatedObject(_ key: UnsafeRawPointer, defaultValue: T) -> T {
guard let value = objc_getAssociatedObject(self, key) as? T else {
View airport-distances
This file has been truncated, but you can view the full file.
AAL ✈️ ABQ | Distance: 8195.183652584217 km
AAL ✈️ ABZ | Distance: 730.2386543388001 km
AAL ✈️ ACC | Distance: 5777.147943540879 km
AAL ✈️ AES | Distance: 644.8547502389752 km
AAL ✈️ AGP | Distance: 2507.4437035749943 km
AAL ✈️ AKL | Distance: 17510.039331730943 km
AAL ✈️ ALA | Distance: 4809.780861544547 km
AAL ✈️ ALC | Distance: 2226.079743224819 km
AAL ✈️ AMM | Distance: 3457.963091935342 km
View ViewController.swift
//
// ViewController.swift
//
// Created by Vitor Venturin Linhalis on 26/11/16.
// Copyright © 2016 Vitor Venturin Linhalis. All rights reserved.
//
import UIKit
import Moya
import RxSwift
View Result.swift
//
// Place.swift
//
// Created by Vitor Venturin Linhalis on 27/11/16.
// Copyright © 2016 Vitor Venturin Linhalis. All rights reserved.
//
import Foundation
import Mapper
View PlaceViewModel.swift
//
// PlaceViewModel.swift
// RxPlaces
//
// Created by Vitor Venturin Linhalis on 17/01/17.
// Copyright © 2017 Vitor Venturin Linhalis. All rights reserved.
//
import UIKit
import RxSwift
View Type.swift
//
// Type.swift
// RxPlaces
//
// Created by Vitor Venturin Linhalis on 12/12/16.
// Copyright © 2016 Vitor Venturin Linhalis. All rights reserved.
//
import Foundation
View Place.swift
//
// Product
//
// Created by Vitor Venturin Linhalis.
// Copyright © 2016 Vitor Venturin Linhalis. All rights reserved.
//
import Foundation
import Mapper