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
// Fibonacci is a Struct that generate an Infinite Array from Fibonacci Numbers. | |
// Fibonacci include a functions with calculate a positions from the Fibonacci Sequence, plus two numbers from this and | |
// The max number will be 2,147,483,647. It's the maximum number from Int. | |
// If want generate number more bigger than 2,147,483,647, you can use Int64 I think. | |
extension Fibonacci { | |
func numberAtIndex (index : Int) -> Int { | |
return ^^index | |
} | |
func plusTwoNumbers(posOne pos : Int, posTwo pos2 : Int) -> Int? { |
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
prefix operator ^^ {} | |
prefix func ^^ (rhs : Int) -> Int { | |
return rhs < 0 ? 0 : rhs <= 2 ? 1 : ^^(rhs - 1) + ^^(rhs - 2) | |
} | |
postfix operator ^^ {} | |
postfix func ^^ (lhs : Int) -> Int { | |
return lhs < 0 ? 0 : lhs <= 2 ? 1 : ^^(lhs - 1) + ^^(lhs - 2) | |
} |
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
postfix operator ~ {} | |
postfix func ~(rhs : Int) -> Int { | |
var result = 1 | |
for i in reverse(1...rhs){ result *= i } | |
return result | |
} | |
infix operator ~/~ { associativity left precedence 150 } | |
func ~/~ (lhs : Int, rhs : Int ) -> Int { | |
assert(lhs > 0, "left number < 0") |
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
'.source.js': | |
'comment function': | |
'prefix': 'comment' | |
'body': """ | |
/** | |
* ${1:function} | |
* Methode: ${2:Type} | |
* @Param ${3:param}: ${4:name} | |
* Return: ${5:return} | |
*/ |
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
/* Two exponentiate algorithms, the first one it's better than second. */ | |
func exponentiate(number : Int, exponent : Int) -> Int { | |
var n = number, e = exponent, r = 1, v = 0 | |
func descriptionVar() -> String { return "Loop v :\(v), n =\(n), e = \(e), r = \(r)" } | |
while (e > 0) { | |
if e%2 != 0 { r = r*n } | |
e /= 2 | |
n *= n | |
v++ |
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
/* | |
Melchoriforme Array is an Array V[1..N] with N >= 0 if some of elements is "rubio". | |
"Rubio" number is an number if your value it's equals to the sum of previous numbers. | |
Example: [1,2,5,8] -> 8 is Rubio because 1 + 2 + 5 = 8. | |
*/ | |
/* | |
This is the predicate. Pass 2 parameters: | |
v -> Array of all elements. | |
num -> value for check if "rubio". |
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; | |
} | |
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
//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
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) |