Skip to content

Instantly share code, notes, and snippets.

@crevier
Last active December 14, 2017 16:27
Show Gist options
  • Save crevier/2d594378a0bb2fe5367295d123daac58 to your computer and use it in GitHub Desktop.
Save crevier/2d594378a0bb2fe5367295d123daac58 to your computer and use it in GitHub Desktop.
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
while (i <= list.size()) {
count = 1
while (list[i - 1] == list[i]) {
count++
i++
}
result.add(count)
result.add(list[i - 1])
count = 1
i++
}
c.add(result)
}
println(c[l-1].join(" "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment