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 reduce<T,R>(list: [T], block: (([R],T) -> R?)) -> [R]? { | |
var acc = [R]() | |
for x in list { | |
if let val = block(acc, x) { | |
acc += [val] | |
} | |
} | |
return acc | |
} |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"sort" | |
"time" | |
) | |
func main() { |
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
enum ShiftDirection { | |
case Left, Right | |
} | |
func shiftBy<T>(shiftDegree: Int, inArray: [T], shiftDirection: ShiftDirection) -> [T] { | |
guard inArray.count > 2 else { | |
return inArray | |
} |
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 highlighted(originalString: String, delimiter:[String]) -> NSMutableAttributedString? { | |
if delimiter.count != 2 { | |
return nil | |
} | |
let highlightedAttributes = [NSForegroundColorAttributeName: UIColor.redColor()] | |
let searchString = originalString.componentsSeparatedByString(delimiter[0]) | |
var attributedResult = NSMutableAttributedString() |
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 UIKit | |
extension String { | |
var length: Int {return count(self)} | |
} | |
func nextBinaryTrialIndex(seriesSize: Int, index: Int, pass: Bool) -> Int? { | |
//Error No case exists | |
if index >= seriesSize || index <= 0 { |
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
def radix (a, base = 10) | |
m = a.max | |
exp = 1 | |
loop do | |
bkt = Array.new(base){[]} | |
a.each{|elem| | |
pos = (elem / exp) % base | |
bkt[pos] << elem | |
} | |
a = bkt.flatten |
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/local/bin/ruby | |
#Get Contents | |
file = File.open(ARGV[0], "r") | |
data = file.read | |
file.close | |
search_results = [] | |
data.each_line{ |line| |
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
=begin | |
This fuction is designed to summarize the contents of a dictionary of arrays. | |
As many elements as possible will be grabbed for a specified size N while maintaining maximum diversity. | |
Function will terminate as soon as the desired amount of items are gathered. | |
Example IO: | |
posts = { 'Greg' => ['A','A','A'], | |
'Steve' => [], |
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
> [fibs x | x <- take 100 [0..]] | |
-- Fibonacci | |
fibs :: Int -> Int | |
fibs hoge | |
| hoge == 0 = 0 | |
| hoge == 1 = 1 | |
| otherwise = fibs_rec | |
where fibs_rec = fibs (hoge - 2) + fibs (hoge - 1) |
NewerOlder