This file contains hidden or 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
//: ## Exercices from https://www.weheartswift.com/higher-order-functions-map-filter-reduce-and-more/ | |
//: This are my solutions. | |
import UIKit | |
//: * Write a function applyTwice(f:(Float -> Float),x:Float) -> Float that takes a function f and a float x and aplies f to x twice i.e. f(f(x)) | |
func applyTwice(f : (Float -> Float), x: Float) -> Float { | |
return f(x) | |
} | |
let r = applyTwice({x in x + 1}, x: 55) |
This file contains hidden or 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
//: #Sort Algorithms - Page 65 Cracking the coding Interview E.4 | |
//: If you have a better solution, please tell me! [email protected] - @JoanMolinas | |
//: ## BubbleSort | |
//: Start at the beginning of an array and swap the first two elements if the first is bigger than the second Go to the next pair, etc, continuously making sweeps of the array until sorted O(n^2) | |
var array:[Int] = [1,3,4,2,34,4,45,3,2,23,345,45] | |
func bubbleSort(array : [Int]) -> [Int]{ | |
let n = array.count |
This file contains hidden or 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
/* Example of SET Collection */ | |
let oddDigits: Set = [1, 3, 5, 7, 9] | |
let evenDigits: Set = [0, 2, 4, 6, 8] | |
let singleDigitPrimeNumbers: Set = [2, 3, 5, 7, 11, 13, 17] | |
let threeFirstNumbers : Set = [1, 2, 3] | |
let threeToOne : Set = [3, 2, 1] | |
let tenToFifteen : Set = [10, 11, 12, 13, 14, 15] | |
//I use var because after `zeroToNine` will be modified. | |
var zeroToNine = Set(oddDigits.union(evenDigits)) |
This file contains hidden or 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
/* ClassCluster Example */ | |
/* Documentation: https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/ClassClusters/ClassClusters.html#//apple_ref/doc/uid/TP40010810-CH4 */ | |
/* This example explicated in Objc: http://stackoverflow.com/questions/1844158/what-exactly-is-a-so-called-class-cluster-in-objective-c */ | |
enum Types { | |
case Guffaw | |
case Giggle | |
} | |
protocol ClassClusterExample { |
This file contains hidden or 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
.include "macros.s" | |
.include "crt0.s" | |
.data | |
F: .word -1 | |
G: .word -2 | |
I: .word 0 | |
.text | |
main: | |
MOVI R6, 0 | |
$MOVEI R1, F |
This file contains hidden or 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
.include "macros.s" | |
.include "crt0.s" | |
.data | |
F: .word 0xBE00 ; 0xBE00 = -1.0 | |
G: .word 0xC000 ; 0xC000 = -2.0 | |
I: .word 0 | |
.text | |
main: | |
MOVI R6, 0 | |
$MOVEI R1, F |
This file contains hidden or 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
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
if (range.location == textField.text.length && [string isEqualToString:@" "]) { | |
textField.text = [textField.text stringByAppendingString:@"\u00a0"]; | |
return NO; | |
} | |
return YES; | |
} |
This file contains hidden or 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 | |
class Queue<T> { | |
private typealias Node = QueueNode<T> | |
private var _top : Node? | |
private var _last : Node? | |
private var _size : UInt = 0 | |
//MARK : Public API |
This file contains hidden or 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 | |
class LinkedList<T : Equatable> { | |
private typealias Node = LinkedListNode<T> | |
private var _head : Node? | |
private var _tail : Node? | |
private var _size : UInt = 0 | |
//MARK : Public API | |
This file contains hidden or 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 | |
class Stack<T> { | |
private typealias Node = StackNode<T> | |
private var _top : Node? | |
private var _size : UInt = 0 | |
//MARK: Public API | |
internal func empty() -> Bool { |