Skip to content

Instantly share code, notes, and snippets.

View mredig's full-sized avatar
🤓
1s and 0s aren't going to put themselves in the right order.

Michael mredig

🤓
1s and 0s aren't going to put themselves in the right order.
View GitHub Profile
@mredig
mredig / Roman numerals.swift
Created June 5, 2019 15:52
roman numerals - it's ugly but it works
import Foundation
extension Int {
subscript(digitIndex: Int) -> Int? {
print(self)
var decimalBase = 1
for _ in 0..<digitIndex {
decimalBase *= 10
}
import Cocoa
extension Int {
static func anotherRandom(_ range: Range<Int>) -> Int {
let floor = range.lowerBound
guard var ceiling = range.last else { fatalError("No last value in range") }
ceiling += 1
let normalCeiling = ceiling - floor
let rando = Int(arc4random_uniform(UInt32(normalCeiling)))
return rando + floor
import Foundation
func AND(_ a: Bool, _ b: Bool) -> Bool {
if a == true {
if b == true {
return true
}
}
return false
}
@mredig
mredig / Int Components
Created May 15, 2019 15:36
separates an Int into each digit (signs negatives)
import Cocoa
extension Int {
func expandNumber() -> [Int] {
var input = self
var signed = false
if input < 0 {
input *= -1
signed = true
}
import Foundation
extension String {
func isAPalindrome() -> Bool {
var string = self.lowercased()
let characterSet = Set("abcdefghijklmnopqrstuvwxyz")
string = string.filter { characterSet.contains($0) }
return string == String(string.reversed())
}
@mredig
mredig / anotherContains.swift
Created May 1, 2019 15:40
swift string contains without contains
import Cocoa
extension String {
func anotherContains(_ string: String) -> Bool {
let lcSelf = self.lowercased()
let lc = string.lowercased()
return lcSelf.range(of: lc) != nil
@mredig
mredig / vowelCount.swift
Created April 24, 2019 15:17
vowel counter
/**
This will count and return the number of vowels in a string. Vowels are defined as "a, e, i, o, and u" and sometimes "y"!
("y" is only counted when there's no other vowel in a word. A word is defined as a string of characters between spaces).
*/
func numberOfVowels(in string: String) -> Int {
let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
let string = string.lowercased()
let words = string.split(separator: " ")
#!/usr/bin/perl
&getStatsFromNames;
&createSourceString;
&printStats;
$count = $ARGV[0];
if($count eq "")
{
$count = 5;