Skip to content

Instantly share code, notes, and snippets.

View joanmolinas's full-sized avatar
🎯
Focusing

Joan Molinas joanmolinas

🎯
Focusing
View GitHub Profile
.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
.include "macros.s"
.include "crt0.s"
.data
F: .word -1
G: .word -2
I: .word 0
.text
main:
MOVI R6, 0
$MOVEI R1, F
/* 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 {
/* 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))
//: #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
//: ## 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)
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)
//New Feature on Swift2
//: # Swift2 Features - Extension Protocol
import Darwin
protocol PrintDescription {
func printDescription() -> String
}
//New Feature on Swift2 doCatch-guard-markup
//: # Swift2 Features - do-Catch
import Darwin
//: Do-Catch type errors
enum DoCatchError : ErrorType {
case DifferentValuesError
}
@joanmolinas
joanmolinas / 1.1.java
Last active August 29, 2015 14:21
Cracking the Coding Interview -> Arrays and String
/* 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;
}