Skip to content

Instantly share code, notes, and snippets.

//https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem
s= new Scanner(System.in);
int n = s.nextInt();
int portee = s.nextInt();
maisons=new TreeSet<>()
for(int x_i=0; x_i < n; x_i++){
maisons.add(s.nextInt())
}
min = maisons.min()
input = new Scanner(System.in);
r = input.nextInt()
l = input.nextInt()
c = [[r],[1,r]]
(2..l-1).each {
List list = c[it - 1]
result = []
i = 1
input = new Scanner(System.in);
N = input.nextInt()
numbers=[]
for (i = 0; i < N; ++i) {
numbers << input.next()
}
int numberOfDigit(List<String> phoneNumbers) {
masterNode = new Node('#')
@crevier
crevier / BowlingGame.groovy
Created December 15, 2017 22:25
Bowling Kata : This snipet is the result of a pair programing session with thomas in Starbuck (avenue de l'opera Paris)
class Bowling {
static int score(def rolls) {
def score = scoreWithoutBonus(rolls)
def frames = 0..9
frames.each {
def firstRollInFrame = it * 2
if (isStrike(rolls, firstRollInFrame)) {
score += strikeBonus(rolls, firstRollInFrame)
} else if (isSpare(rolls, firstRollInFrame)) {
score += spareBonus(rolls, firstRollInFrame)
@crevier
crevier / codeGolf.groovy
Last active December 18, 2017 11:38
script template used for code golf on codingame
/*
This is a script template used for code golf on codingame
use scriptSize to compute the size of the code between two tags
use runCode to execute the golfCode with custom STDIN/OUT for your unit tests
*/
/**
* Read this file lines and return the number of char between two line marked with the given tags
* @param startTag the tag of the starting line ex : //START
* @param endTag the tag of the end line ex : //END
import java.util.Arrays;
public class StairCaseSolution {
public static String staircase(int n) {
if (n <= 0)
return "";
StringBuilder resultBuilder = new StringBuilder();
for (int spaceNumber = n - 1; spaceNumber >= 0; spaceNumber--) {
resultBuilder.append(createLine(n, spaceNumber)).append('\n');
}
@crevier
crevier / InMemoryAppender.java
Created March 5, 2018 16:34
Log4j2 InMemoryAppender for tests
package log.appender;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
@crevier
crevier / Bowling.java
Last active March 15, 2018 15:51
Bowling kata - constrains : fake outside in and golf.
import org.junit.Test;
import static java.util.Arrays.stream;
import static java.util.stream.IntStream.range;
import static org.junit.Assert.assertEquals;
public class Bowling {
private int score(int[][]f) {
return range(0,9).boxed().mapToInt(i->stream(f[i]).sum()+((f[i][0]+f[i][1]==10)?f[i+1][0]:0)+((f[i][0]==10)?(f[i+1][0]!=10?f[i+1][1]:(i!=8?f[i+2][0]:f[i+1][2])):0)).sum()+stream(f[9]).sum();
}
@crevier
crevier / colorInConsole.groovy
Created June 13, 2018 14:21
How to print color in console in groovy
def fg = 30
def bg = 46
def style = "${(char)27}[$fg;$bg"+"m"
println(style+"HELLO")
/*
+~~~~~~+~~~~~~+~~~~~~~~~~~+
| fg | bg | color |
+~~~~~~+~~~~~~+~~~~~~~~~~~+
| 30 | 40 | black |
| 31 | 41 | red |
@crevier
crevier / consoleProgressBar.groovy
Created June 14, 2018 14:05
quick and dirty progress bar in groovy for cli
def progressColor(int percent) {
def red = "${(char) 27}[31;49m"
def yellow = "${(char) 27}[33;49m"
def green = "${(char) 27}[32;49m"
if (percent <= 25)
return red
if (percent <= 75)
return yellow
return green
}