This file contains 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
public static function dateDiff( date1:Date, date2:Date ) : String { | |
// calculando a diferença em milisegundos das datas | |
var sec:Number = date2.getTime() - date1.getTime(); | |
// verificando se a segunda data é inferior que a primeira | |
if( sec < 0 ) { | |
Alert.show( "The second date ocurred earlier than the first one!" ); | |
return null; | |
} |
This file contains 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
''' | |
Curiosidades do Python e estruturas de loop | |
uma delas temos a funcao range a qual nos possibilita criar um array | |
facilmente... | |
ex.: | |
arr = range(10) |
This file contains 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 math | |
def aumentoPercentual(valorInicial, valorPercentual): | |
resultado = math.ceil( valorInicial * valorPercentual ) | |
return valorInicial + resultado | |
def reducaoPercentual(valorInicial, valorPercentual): | |
resultado = math.ceil( valorInicial * valorPercentual ) | |
return valorInicial - resultado |
This file contains 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
def fatorial(n, limite=1): | |
if n == 0 or n == 1: | |
return 1 #por definição 0! ou 1! = 1 | |
if limite < 1 or limite >= n: | |
return -1 #representando valor incorreto | |
else : | |
fatArr = range(limite,n+1) | |
resultado = 1 | |
for i in fatArr: | |
resultado = resultado * i |
This file contains 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
def binaryStringCalc(strValue): | |
result = 0 | |
for v in strValue.split(' + '): | |
result += int(v,2) | |
return str(bin(result)).split('0b')[1] | |
print binaryStringCalc('110000001 + 100111001 + 100101000 + 10000011 + 111010001') |
This file contains 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
''' | |
Really elementary | |
A box contains some buttons. | |
1/4 of them are black, | |
1/8 of them are red, | |
and the rest are white. | |
There are 636 more white buttons than red buttons. | |
How many buttons are there altogether? |
This file contains 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
''' | |
If 1 bucket of food feed 2 donkeys for 3 days, | |
how many buckets are needed to feed 1314 donkeys for 1 day? | |
donkeys | days | buckets | |
n | 1 | x | |
2 | 3 | 1 | |
x = n/2 * 1/3 |
This file contains 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
''' | |
The nth term | |
1,1,2,3,5,8,13,21,34,55,89 ... | |
Give the 119 th term. | |
''' | |
def fib(n): | |
a, b = 0, 1 | |
r = [] |
This file contains 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
# -*- coding: latin1 -*- | |
from math import sqrt | |
from time import time | |
''' | |
Implementar uma função que retorne verdadeiro se o | |
número for primo (falso caso contrário). Testar de 1 a 100. | |
''' | |
# verifica se o número é um valor inteiro |
This file contains 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
### | |
uma possível justificativa para utilizar o CoffeScript, ele possibilita codificar mais próximo do conceito de POO de linguagens como o Java, C#, ... | |
http://js2coffee.org/ | |
faça um teste na aba: CoffeeScript > JS | |
### | |
class ClassA | |
@att1 = "atributo 1" | |
@att2 = "atributo 2" |
OlderNewer