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
.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
/* 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
/* 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
//: #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
//: ## 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
var numbers = [Int]() | |
func appendNumbers() { | |
numbers.append(3) | |
//: defer{} is executed in the final on the function | |
//: use defer{} when you want that any code run it always whatever the function result | |
defer {numbers.append(4)} | |
numbers.append(5) | |
} | |
numbers.append(1) |
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
//New Feature on Swift2 | |
//: # Swift2 Features - Extension Protocol | |
import Darwin | |
protocol PrintDescription { | |
func printDescription() -> String | |
} |
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
//New Feature on Swift2 doCatch-guard-markup | |
//: # Swift2 Features - do-Catch | |
import Darwin | |
//: Do-Catch type errors | |
enum DoCatchError : ErrorType { | |
case DifferentValuesError | |
} |
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
/* Implement an algorithm to determine if a string has a all unique characters. What if tou can not use additional data Structures? */ | |
/* Book Solution */ | |
public boolean isUniqueChars(String s) { | |
boolean[] char_set = new boolean[256]; | |
for (int i = 0; i < s.length(); i++) { | |
int val = s.charAt(i); | |
if(char_set[val]) return false; | |
char_set[val] = true; | |
} | |