Permalink
Browse files

adicionando dojo do dia 09 de Agosto de 2001. Renomeando as pastas pa…

…ra ficar mais fácil de identificar os dias
  • Loading branch information...
Diogo Santos
Diogo Santos committed Aug 10, 2011
1 parent bad674a commit 330bdbc55203cd0bf48750624854188ddaf555a0
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>mundopequeno</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue May 24 18:44:16 BRT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,28 @@
+
+class Amigo {
+ def id
+ def coordenada
+
+ def Amigo(id, x , y) {
+ this.id = id
+ coordenada = new Coordenada(x:x, y:y)
+ }
+
+ def comparaDistancia(amigo){
+ ((coordenada.x- amigo.coordenada.x)**2 + (coordenada.y - amigo.coordenada.y)**2)**0.5
+ }
+
+ def encontrarAmigosProximos(amigos){
+ def res = amigos.findAll{
+ it.id != this.id
+ }.collect{ amigo ->
+ [id:amigo.id, dist: comparaDistancia(amigo)]
+ }
+
+ res.sort{
+ it.dist
+ }
+
+ [ res[0].id, res[1].id ,res[2].id ].sort()
+ }
+}
@@ -0,0 +1,8 @@
+
+class Coordenada {
+
+ def x, y
+
+
+
+}
@@ -0,0 +1,12 @@
+
+class MundoPequeno {
+
+ def amigos
+ // beijo mãe
+ public MundoPequeno(amigos){
+ this.amigos = amigos
+ }
+
+
+
+}
@@ -0,0 +1,58 @@
+import static org.junit.Assert.*;
+import junit.framework.TestCase
+
+
+class MundoPequenoTests extends TestCase {
+
+ def amigos = [
+ new Amigo(1,2,4),
+ new Amigo(2,3,6),
+ new Amigo(3,4,4),
+ new Amigo(4,5,5),
+ new Amigo(5,7,6)
+ ]
+
+
+ //alt + shit + a
+ void testBusca3AmigosProximosAoAmigo5(){
+ def atual = amigos[4]
+ def res = atual.encontrarAmigosProximos(amigos)
+
+ assert([2,3,4]==res)
+ }
+
+ void testBusca3AmigosProximosAoAmigo1() {
+ def atual = amigos[0]
+ def res = atual.encontrarAmigosProximos(amigos)
+
+ assert([2,3,4]==res)
+ }
+
+ void testBusca3AmigosProximosAoAmigo2() {
+ def atual = amigos[1]
+ def res = atual.encontrarAmigosProximos(amigos)
+
+ assert([1,3,4]==res)
+ }
+
+ void testBusca3AmigosProximosAoAmigo3() {
+ def atual = amigos[2]
+ def res = atual.encontrarAmigosProximos(amigos)
+
+ assert([1,2,4]==res)
+ }
+
+ void testBusca3AmigosProximosAoAmigo4() {
+ def atual = amigos[3]
+ def res = atual.encontrarAmigosProximos(amigos)
+
+ assert([2,3,5]==res)
+ }
+
+ void testComparaDuasDistancias() {
+ def atual = amigos[1]
+ def res = atual.comparaDistancia(amigos[1]);
+ assert(0==res)
+ }
+
+}
@@ -0,0 +1,16 @@
+def sacar(valor, notas_disponiveis = {100:0, 50:0, 20:0, 10:0}):
+ retorno = []
+ notas_disponiveis.each { qtd ->
+
+ }
+ for qtd in notas_disponiveis.items() :
+ print nota
+ if nota <= valor:
+ div = valor / nota
+ if (div <= qtd) :
+ retorno.extend([nota] * div)
+ valor = valor - (nota * div)
+ notas_disponiveis[nota] -= div
+
+ return retorno
+
Binary file not shown.
@@ -0,0 +1,25 @@
+import unittest
+from caixa_eletronico import sacar
+
+class CaixaEletronicoTest(unittest.TestCase):
+
+ def test_sacar_10_reais_sem_nota_disponivel(self):
+ self.assertEquals([], sacar(10))
+
+ def test_sacar_30_reais_sem_nota_disponivel(self):
+ self.assertEquals([], sacar(30))
+
+ def test_sacar_20_reais_tendo_apenas_nota_20_disponivel(self):
+ self.assertEquals([20], sacar(20,{20:1}))
+
+ def test_sacar_20_reais_tendo_apenas_nota_10_disponivel(self):
+ self.assertEquals([10,10], sacar(20,{10:2}))
+
+ def test_sacar_50_reais_tendo_apenas_nota_10_e_20_disponivel(self):
+ self.assertEquals([20, 20, 10], sacar(50,{20:2, 10:2}))
+
+
+
+
+
+unittest.main()
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Buraco</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue Jul 19 19:24:27 BRT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,69 @@
+import junit.framework.TestCase
+
+class BuracoTest extends TestCase {
+
+ def pontuacoes = [ 1:15, 2:10, 3:5, 4:5, 5:5, 6:5, 7:5, 8:10, 9:10, 10:10, 11:15, 12:15, 13:15 ]
+
+ void testSeSequenciaEhCanastra() {
+ assertEquals(15, contaCanastra([4,5,6]) )
+ }
+
+ void testNaoCanastra() {
+ assertEquals(0, contaCanastra([4, 8, 11]))
+ }
+
+ void testCanastraMaiorValorComTresCartas() {
+ assertEquals(45, contaCanastra([11, 12, 13]))
+ }
+
+ void testCanastraMenor() {
+ assertEquals(15, contaCanastra([3, 4, 5]))
+ }
+
+ void testSeSequencia(){
+ assertEquals(true, isSeq([3, 4, 5]))
+ }
+
+ void testSeSequenciaComNumerosIguais(){
+ assertEquals(false, isSeq([1, 1, 1]))
+ }
+
+ void testSeSequenciaComCoringaPrimeiraPosicao(){
+ assertEquals(true, isSeq([2, 4, 5]))
+ }
+
+ void testSeSequenciaComCoringaSegundaPosicao(){
+ assertEquals(true, isSeq([3, 2, 5]))
+ }
+
+ void testSeSequenciaComCoringaTerceiraPosicao(){
+ assertEquals(true, isSeq([3, 2, 2]))
+ }
+
+ void testCanastraCompleta() {
+ assertEquals(1000, contaCanastra([1,2,3,4,5,6,7,8,9,10,11,12,13,1]))
+ }
+
+ int contaCanastra(def cartas) {
+ if(cartas == [1,2,3,4,5,6,7,8,9,10,11,12,13,1]) return 1000
+ def soma = 0
+ if (isSeq(cartas)) {
+ cartas.each {
+ soma = soma + pontuacoes[it]
+ }
+ }
+ return soma
+ }
+
+ boolean isSeq(def cartas){
+ for(int i = 0; i < cartas.size()-1;i++){
+ if(cartas[i]+1 != cartas[i+1]){
+ if(cartas[i] != 2 && cartas[i+1] != 2) {
+ return false
+ }
+ }
+ }
+ return true
+ }
+
+}
@@ -0,0 +1,57 @@
+class Intervalos
+
+ def get_intervalo(lista_numeros)
+ lista_numeros.sort!
+
+ if lista_numeros.size <= 1
+ return [lista_numeros]
+ end
+
+ if is_intervalo? lista_numeros
+ return [ [lista_numeros.first, lista_numeros.last] ]
+ else
+ return monta_sub_intervalo lista_numeros
+ end
+
+ #[lista_numeros]
+ end
+
+ private
+
+ def is_intervalo?(lista_numeros)
+ if lista_numeros.size <= 1
+ return false
+ end
+
+ if lista_numeros[0] + (lista_numeros.size - 1) ==
+ lista_numeros[lista_numeros.size-1]
+ true
+ end
+ end
+
+ def monta_sub_intervalo(lista_numeros)
+ listas = []
+ interval = []
+ lista_numeros.each_with_index do | item, index |
+ if index == (lista_numeros.size -1)
+ if is_intervalo? [interval.last, item]
+ interval.push item
+ else
+ listas << [interval.first,interval.last]
+ interval = [item]
+ end
+
+ listas << [interval.first,interval.last]
+
+ elsi f item != (lista_numeros[index + 1] - 1)
+ interval.push item
+ listas << [interval.first, interval.last]
+ interval = []
+ else
+ interval.push item
+ end
+ end
+
+ listas
+ end
+end
Oops, something went wrong.

0 comments on commit 330bdbc

Please sign in to comment.