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 groovy.time.* | |
def inp = "https://pastebin.com/raw/Sk5ekVUD".toURL().text | |
def timeStart = new Date() | |
def (inpRules, inpTicketOwn, inpTicketsOthers) = inp.split("\r?\n\r?\n").collect{ it.split("\r?\n") } | |
def rules = inpRules.collect { | |
(all, name, min1, max1, min2, max2) = (it =~ /([^:]+): (\d+)-(\d+) or (\d+)-(\d+)/)[0] | |
[name: name, min1: min1.toInteger(), max1: max1.toInteger(), min2: min2.toInteger(), max2: max2.toInteger()] | |
} |
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 groovy.time.* | |
def inp = "https://pastebin.com/raw/UicYsA3q".toURL().text.split("\r?\n")[1] | |
def timeStart = new Date() | |
def eukl //Erweiterter euklidischer Algo. | |
eukl = { a, b -> | |
if (b == 0) { return [a, 1, 0] } | |
else { | |
(g, u, v) = eukl(b, a%b) |
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 groovy.time.* | |
def inp = "https://pastebin.com/raw/UicYsA3q".toURL().text.split("\r?\n") | |
def timeStart = new Date() | |
def solution = inp[1].split(",").findAll{ it != "x" }.collect { | |
def i = it.toInteger() | |
[i, i - inp[0].toInteger() % i] | |
}.min{ a, b -> a[1] <=> b[1] }.inject(1){ a, b -> a*b } |
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 groovy.time.* | |
import java.security.MessageDigest | |
def inp = "https://pastebin.com/raw/yYv4N9pU".toURL().text | |
def timeStart = new Date() | |
def posS = [0,0], posWp = [10,-1] | |
def cmds = inp.split("\r?\n").each { | |
(total, dir, param) = (it =~ /(\w)(\d+)/)[0] | |
def val = param.toInteger() |
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 groovy.time.* | |
import java.security.MessageDigest | |
def inp = "https://pastebin.com/raw/yYv4N9pU".toURL().text | |
def timeStart = new Date() | |
def cmdToDir = { currDir, turn, rad -> | |
def dirs = ["N", "E", "S", "W" ] | |
dirs[(dirs.findIndexOf { it == currDir } + ((turn=="R"?1:-1)*rad / 90)).toInteger() % 4] | |
} |
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 groovy.time.* | |
import java.security.MessageDigest | |
def inp = "https://pastebin.com/raw/w1SNfxSw".toURL().text | |
def timeStart = new Date() | |
def printSeats = { sMap -> sMap.each{ println it.join() } } | |
def md5 = { s -> MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() } | |
def hashSeats = { sMap -> md5(sMap.collect{ it.join() }.join()) } | |
def isSeatOccupied = { seatMap, x, y, filledSeats -> |
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 groovy.time.* | |
import java.security.MessageDigest | |
def inp = "https://pastebin.com/raw/w1SNfxSw".toURL().text | |
def timeStart = new Date() | |
//Helper functions | |
def printSeats = { sMap -> sMap.each{ println it.join() } } | |
def md5 = { s -> MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() } | |
def hashSeats = { sMap -> md5(sMap.collect{ it.join() }.join()) } |
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 groovy.time.* | |
def inp = "https://pastebin.com/raw/mKNM0xdT".toURL().text | |
def timeStart = new Date() | |
def nmbrs = inp.split("\r?\n").collect { it.toLong() } | |
def tgt = 507622668L | |
0.upto(nmbrs.size()-2) { i1 -> | |
def i2 = i1+2, candidates = [nmbrs[i1], nmbrs[i1+1]] |
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 groovy.time.* | |
def inp = "https://pastebin.com/raw/mKNM0xdT".toURL().text | |
def timeStart = new Date() | |
def sLen = 25 | |
def nmbrs = inp.split("\r?\n").collect { it.toLong() } | |
sLen.upto(nmbrs.size()-1) { i -> | |
def predecessors = nmbrs.withIndex().findAll{ val, ind -> ind >= i-sLen && ind <= i-1 }.collect { it[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
import groovy.time.* | |
def inp = "https://pastebin.com/raw/mXaaQwKh".toURL().text | |
def timeStart = new Date() | |
def fac = { n -> (n == 1) ? 1 : n * call(n - 1) } | |
def adapters = [[0],inp.split("\r?\n").collect { it.toInteger() }].flatten().sort() | |
adapters << adapters.max()+3 |
NewerOlder