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
d={'z':'q','q':'z','\n':'\n',' ':' ','a':'y','c':'e','b':'h','e':'o','d':'s','g':'v','f':'c','i':'d','h':'x','k':'i','j':'u','m':'l','l':'g','o':'k','n':'b','p':'r','s':'n','r':'t','u':'j','t':'w','w':'f','v':'p','y':'a','x':'m'} | |
inf=open('file.in') | |
l1=int(inf.readline()) | |
ouf=open('file.out','w') | |
def trans(l): | |
return ''.join(d[x] for x in l) | |
for i in range(l1): | |
ouf.write('Case #%s: %s'%(i+1, trans(inf.readline()))) |
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
List list = [ | |
[id:0, firstName: 'Sachin', lastName: 'Tendulkar', age: 40 ], | |
[id:1, firstName: 'Sachin', lastName: 'Tendulkar', age: 103 ], | |
[id:2, firstName: 'Ajay', lastName: 'Tendulkar', age: 48 ], | |
[id:3, firstName: 'Virendra', lastName: 'Sehwag', age: 5 ], | |
[id:4, firstName: 'Virendra', lastName: 'Sehwag', age: 50 ], | |
[id:5, firstName: 'Sachin', lastName: 'Nayyar', age: 15 ] | |
] | |
println list.sort { a,b -> a.firstName <=> b.firstName ?: a.lastName <=> b.lastName ?: a.age <=> b.age}*.id |
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
#Eu sei que codigo ta porquinho, mas foi so para matar a curiosidade! rsrs | |
def d(): | |
do = int(raw_input('informe o dividendo: ')) | |
dr = int(raw_input('informe o divisor: ')) | |
m = do*dr | |
l = [] | |
while(m > 0): | |
l.append(m) | |
m -= dr | |
c = 0 |
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
//Implementação do FizzBuzz semântico: Veja também a implementação rápida - https://gist.github.com/3438973 | |
seMultiploDeCinco = {it%5==0}; seMultiploDeTres = {it%3==0} | |
fizzbuzz = {seMultiploDeTres (it) & seMultiploDeCinco (it) ? 'fizzbuzz': | |
seMultiploDeTres (it) ? 'fizz': | |
seMultiploDeCinco (it) ? 'buzz': | |
'Without fizzbuzz!'} | |
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
// Implementação rápida! : Veja também a implementação semântica - https://gist.github.com/3438630 | |
fizzbuzz = {it%3==0 & it%5==0 ? 'fizzbuzz' : it%3 == 0 ? 'fizz' : it%5==0 ? 'buzz' : 'Without fizzbuzz!'} |
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
//Segue outros asserts que tambem podem ser utilizados nos testes unitarios do groovy. | |
void assertArrayEquals(Object[]expected, Object[] value) //Compares the contents and length of each array void assertLength(int length, char[] array) Convenience method for asserting the length of an array | |
void assertLength(int length,int[] array) //Convenience method for asserting the length of an array | |
void assertLength(int length,Object[] array) //Convenience method for asserting the length of an array | |
void assertContains(char expected,char[] array) //Verifies that a given array of chars contains an expected value |
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
//Problema: Quando temos um loop e dentro dele temos uma determinada | |
//lógica que precisará ser executada em todas as iterações; | |
(1..10).each{println "este numero é ${it+5*(10-1)}"} | |
//Solução: Podemos otimizar nosso código inserindo nossa lógica dentro | |
//de uma closure, onde ao final desta chamamos o método memoize(). | |
c = {println "este numero é ${it+5*(10-1)}"}.memoize() | |
//Por fim, chamamos esta closure de dentro do loop para que apenas a primeira | |
//interação seja 100% processada, pois nas próximas a parte repetida desta |
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
//Ainda não sei em detalhes o motivio, mas por acaso percebi que tenho uma | |
//resposta mais rápida quando executo operações matemáticas utilizando os métodos fornecidos pelo Number em questão | |
def start1 = System.nanoTime() | |
100.times{ 150.div(3) } | |
def stop1 = System.nanoTime() | |
println "150.div(3) : "+stop1 - start1 | |
def start2 = System.nanoTime() | |
100.times{ 150/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
def t = 1..100 | |
def v = [] | |
t.each { n -> | |
(2..n).each { d -> | |
if (n % d == 0 && n != d) | |
v.add(n) | |
} | |
} |
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
// font: http://www.groovyexamples.org/2010/06/21/create-a-csv-file/ | |
//For this example, let’s assume we have an array of maps as our data. | |
def planets = [ | |
[id:'1',color:'red',planet:'mars',description:'Mars, the "red" planet'], | |
[id:'2',color:'green',planet:'neptune',description:'Neptune, the "green" planet'], | |
[id:'3',color:'blue',planet:'earth',description:'Earth, the "blue" planet'], | |
] | |
//Next, we can create our CSV file as follows: |
OlderNewer