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
/* 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
'.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
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
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
// 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
infix operator ** { associativity left precedence 160 } | |
postfix operator ** {} | |
func ** (lhs: Double, rhs: Double) -> Double { | |
return pow(lhs, rhs) | |
} | |
postfix func **(rhs : Int) -> Int { | |
return rhs * rhs | |
} |
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
//Note : this is just an experimental, only works with "1", working for works with any number | |
//In mathematics a polydivisible number is a number with digits abcde... that has the following properties : | |
//Its first digit a is not 0. | |
//The number formed by its first two digits ab is a multiple of 2. | |
//The number formed by its first three digits abc is a multiple of 3. | |
//The number formed by its first four digits abcd is a multiple of 4..etc | |
extension Int { | |
func numberOfDigits () -> Int { | |
var cont = 0, num = self |
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
//At this moment, this is my solution. I working for a better solution. | |
var n1 = 381654729 | |
var n2 = 102 | |
var n3 = 9876 | |
var n4 = 67 | |
extension Int { | |
func numberOfDigits () -> Int { | |
var cont = 0, num = self |
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
//Select prime number from array. | |
let primeNumbers = numbers.filter{ | |
(number) in | |
for var i = 2; i <= number/2; i++ { | |
if number%i == 0 { return false } | |
} | |
return true | |
} |