Skip to content

Instantly share code, notes, and snippets.

=begin
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.
Example
The maximum height candles are units high. There are of them, so return .
Function Description
@jluismm2311
jluismm2311 / application.txt
Created September 2, 2020 16:08
Interview rest test
Construir una api REST, para hacer altas, bajas cambios de usuarios, documentar la API.
Utilizar las siguientes tecnologias.
* Spring Boot
* PostgreSQL hibernate o Gorm
* Gradle
La aplicacion debe de estar versionada en GitHub y de correr con el comando: gradle bootRun
Se va a correr una prueba funcional a la API.
@jluismm2311
jluismm2311 / ClockMirror.groovy
Created June 9, 2020 17:19
Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 alt text He knows that the time is 11:38 alt text in the same manner: 05:25 --> 06:35 01:50 --> 10:10 11:58 --> 12:02 12:01 --> 11:59 Please complete the function WhatIsTheTime(timeInMirror), where timeInMirror is the mirrored time (what P…
class Kata {
static String WhatIsTheTime(timeInMirror) {
def hoursAndMinutes = timeInMirror.split(':').collect{it.toInteger()}
def hours = hoursAndMinutes[1] == 0? 12 :11
if(hoursAndMinutes[0] < 12) {
hoursAndMinutes[0] = hours-hoursAndMinutes[0]== 0?12:hours-hoursAndMinutes[0]
}else{
hoursAndMinutes[0] = hours
}
@jluismm2311
jluismm2311 / CategorizeNewMember.groovy
Created June 8, 2020 22:55
The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be placed. To be a senior, a member must be at least 55 years old and have a handicap greater than 7. In this croquet club, handicaps range from -2 to +…
class Kata {
static def openOrSenior(data) {
data.collect{def values ->
values.first() >=55 && values[1] > 7? 'Senior': 'Open'
}
}
}
@jluismm2311
jluismm2311 / TortoiseRacing.groovy
Created May 28, 2020 23:57
Two tortoises named A and B must run a race. A starts with an average speed of 720 feet per hour. Young B knows she runs faster than A, and furthermore has not finished her cabbage. When she starts, at last, she can see that A has a 70 feet lead but B's speed is 850 feet per hour. How long will it take B to catch A? More generally: given two spe…
public class Tortoise {
public static int[] race(int v1, int v2, int g) {
if (v1 >= v2)
return null
def averageTime = (g*3600).intdiv(v2-v1)
[averageTime.intdiv(3600), averageTime.mod(3600).intdiv(60), averageTime.mod(3600).mod(60)]
}
}
@jluismm2311
jluismm2311 / SummingAnumberDigits.groovy
Last active May 28, 2020 22:16
Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits.
class Kata{
static int sumDigits(number) {
"${number.abs()}".toList().collect{it.toInteger()}.value.sum()
}
}
package com.groovy.testDictionary
class Dictionary {
def key
def value
def dict = [:]
Dictionary (){}
Dictionary (def key, def value){
import java.util.*;
public class TreeNode {
TreeNode left;
TreeNode right;
public static boolean isPerfect(TreeNode root) {
if(root == null){
return true;
import java.util.*;
public class Solution {
static TreeNode arrayToTree(int[] array) {
TreeNode root = null;
if(array.length > 0){
Queue<TreeNode> queue = new LinkedList<TreeNode>();
TreeNode treeNode = new TreeNode(array[0]);
queue.add(treeNode);
@jluismm2311
jluismm2311 / StringUtils.java
Last active April 28, 2016 21:08
Implement String#hex_number? (in Java StringUtils.isHexNumber(String)), which should return true if given object is a hexadecimal number, false otherwise. Hexadecimal numbers consist of one or more digits from range 0-9 A-F (in any case), optionally prefixed by 0x.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils {
public static boolean isHexNumber(String s) {
boolean b = false;
if(s != null){
Pattern p = Pattern.compile("^(0x)?[\\dA-Fa-f]+$");
Matcher m = p.matcher(s);