This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
&getStatsFromNames; | |
&createSourceString; | |
&printStats; | |
$count = $ARGV[0]; | |
if($count eq "") | |
{ | |
$count = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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: " ") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
extension String { | |
func anotherContains(_ string: String) -> Bool { | |
let lcSelf = self.lowercased() | |
let lc = string.lowercased() | |
return lcSelf.range(of: lc) != nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
extension Int { | |
func expandNumber() -> [Int] { | |
var input = self | |
var signed = false | |
if input < 0 { | |
input *= -1 | |
signed = true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func AND(_ a: Bool, _ b: Bool) -> Bool { | |
if a == true { | |
if b == true { | |
return true | |
} | |
} | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Int { | |
subscript(digitIndex: Int) -> Int? { | |
print(self) | |
var decimalBase = 1 | |
for _ in 0..<digitIndex { | |
decimalBase *= 10 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a twin prime is where a prime number +/- 2 is another prime number. For example, 3 is prime, and so is 5. They are twin primes. (Since 7 is 2 away from 5 as well, maybe that makes them triplets! But I'm not a mathematician. I'll let them decide.) | |
extension FixedWidthInteger { | |
func isPrime() -> Bool { | |
// negatives, 0, and 1 are all not prime and will break the range created below | |
guard self >= 2 else { return false } | |
// no even numbers are prime, except 2 | |
guard !self.isMultiple(of: 2) else { | |
return self == 2 ? true : false |
OlderNewer