-
Notifications
You must be signed in to change notification settings - Fork 3
/
solve.groovy
executable file
·38 lines (30 loc) · 903 Bytes
/
solve.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env groovy
def scriptFile = new File(args[0])
// Else fall back to generic
if (!scriptFile.exists()) {
scriptFile = new File("src/groovy/${args[0]}.groovy")
}
if (!scriptFile.exists()) {
def scriptsDir = new File('src/groovy')
def fileName = scriptsDir.list().find { it.matches("Problem${args[0]}_.+") }
if (!fileName) {
println "${args[0]} not found."
return 1
}
scriptFile = new File('src/groovy', fileName)
}
if (!scriptFile.exists()) {
println "File '${scriptFile.absolutePath}' not found"
return 1
}
def script = new GroovyShell().evaluate(scriptFile.text)
def title = " ${script.title()} "
while (title.size() < 100) {
title = "*${title}*"
}
println ''
println title
println script.description()
def start = System.currentTimeMillis()
println "Answer: ${script.solve()} in ${System.currentTimeMillis() - start}ms"
println ''