Created
February 21, 2013 16:26
-
-
Save kiy0taka/5005926 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
enum Direction { L,U,R,D } | |
def debug = { directions, button = null -> | |
def result = """|3${directions[3]}0 | |
|${directions[2]} ${directions[0]} | |
|2${directions[1]}1""".stripMargin() | |
if (button != null) result = result.replace("$button", '*') | |
result | |
} | |
int combinationCount = 0 | |
8.times { combinationCount += 4.power(it+1) } | |
def result = (0..<combinationCount).findResult { int n -> | |
def buttons = [n%4] | |
while ((n = (int) n / 4)) { | |
buttons << (--n%4) | |
} | |
def directions = args.collect { Direction.valueOf(it) } | |
def history = [debug(directions)] | |
buttons.each { btn -> | |
directions.eachWithIndex { d, i -> | |
directions[i] = i == btn ? d : ++d | |
} | |
history << debug(directions, btn) | |
} | |
directions == Direction.values() ? history : null | |
} | |
println result?.join('\n----\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment