Parsing
Converting strings to integers
x.toInteger()
x as Integer
x as int
Looping through list/string
for(a:args){a} // Java-style syntax; braces may be omitted if the body is only one statement
args.any{it} // Must return falsy value to keep iterating
args.min{it} // Sometimes useful for non-falsy values
args.each{it} // Most general iteration method, but rarely optimal
Looping through integers
10.times{}
for(n:0..9){} // better than .times when the variable is used at least twice and braces aren't needed
0.upto(10){}
(0..9).any{} // or any other list methods
0.step(10,2){} // loop with a step
Misc
- Eval -
Eval.me()
, or evaluate()
to have access to current scope (Warning: slow)
- Short-circuiting is allowed:
i%2||println(i)
- Regex matching:
x.matches("...")
-> x=~/.../
- Use spread-dot instead of
collect
to apply a method call to all elements in a collection: x*.multiply(2)
Packers
2:1
Spoiler
Decompressor
evaluate new String('...'.getBytes('UTF-16LE'))
If the hole has no arguments, Eval.me
may be used instead of evaluate
to save 1 byte.
Compressor
# python
print('CODE'.encode().decode('utf-16le'))