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
func fizzbuzz(i: Int) -> String { | |
let result = (i % 3, i % 5) | |
switch result { | |
case (0, _): | |
return "Fizz" | |
case (_, 0): | |
return "Buzz" | |
case (0, 0): | |
return "FizzBuzz" | |
default: |
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
extension String { | |
func stripCharSet(charSet:NSCharacterSet) -> String{ | |
let tempstring:NSArray = self.componentsSeparatedByCharactersInSet(charSet) | |
let returnString = tempstring.componentsJoinedByString("") | |
return returnString | |
} | |
var stripWhiteSpace:String { get { | |
return stripCharSet(.whitespaceAndNewlineCharacterSet()) | |
}} |
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
infix operator ** { associativity left precedence 160 } | |
func ** (num: Double, power: Double) -> Double{ | |
return pow(num, power) | |
} |
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
func pow(lhs:Int, rhs:Int)->Double{ | |
return pow(Double(lhs),Double(rhs)) | |
} | |
func pow(lhs:Double, rhs:Int)->Double{ | |
return pow(lhs,Double(rhs)) | |
} |
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
//http://stackoverflow.com/questions/5811151/why-do-we-check-upto-the-square-root-of-a-prime-number-to-determine-if-it-is-pri | |
func isPrime(n: Int) -> Bool { | |
if n < 2 { | |
return false // are not primes | |
} | |
var limit = Int(sqrt(Float(n))) | |
if limit < 2 { | |
return true // 2, 3 are primes | |
} |
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
extension String{ | |
func substringFromIndexInt(indx:Int) -> String { | |
let index = advance(self.startIndex, indx) | |
return self.substringFromIndex(index) | |
} | |
func substringWithRangeInt(intRange:Range<Int>)->String{ | |
let start = advance(self.startIndex,intRange.startIndex) | |
let end = advance(self.startIndex,intRange.endIndex) | |
return self.substringWithRange(start..<end) |
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
extension Array{ | |
func indexInbound (index: Int) -> Bool{ | |
if 0 <= index && index < count { | |
return true | |
} else { | |
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
// | |
// Queue.swift | |
// NTBSwift | |
// | |
// Created by Kåre Morstøl on 11/07/14. | |
// | |
// Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks. | |
// should be an inner class of Queue, but inner classes and generics crash the compiler, SourceKit (repeatedly) and occasionally XCode. |
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
//http://www.raywenderlich.com/86205/nsregularexpression-swift-tutorial | |
func highlightMatches(pattern: String, inString string: String) -> NSAttributedString { | |
let regex = NSRegularExpression(pattern: pattern, options: .allZeros, error: nil) | |
let range = NSMakeRange(0, countElements(string)) | |
let matches = regex?.matchesInString(string, options: .allZeros, range: range) as [NSTextCheckingResult] | |
let attributedText = NSMutableAttributedString(string: string) | |
for match in matches { |
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
wget -P /Users/temp -mpck --user-agent="" -e robots=off --wait 1 -E --no-check-certificate https://cs.byu.edu/colloquia_files/2006Fall/presentations/Matz_slides/index.html | |
//where /Users/temp is the destination folder |