Skip to content

Instantly share code, notes, and snippets.

@keesun
Created September 6, 2012 04:22
Show Gist options
  • Save keesun/3651199 to your computer and use it in GitHub Desktop.
Save keesun/3651199 to your computer and use it in GitHub Desktop.
package sclass
/**
* @author Keesun Baik
*/
class AntProgression {
def next(num: String): String = {
val charList: List[Char] = num.toList
var nums: Map[Char, Int] = Map()
for (i <- 0 until charList.length) {
if (nums.get(charList(i)) == None){
nums += (charList(i) -> 1)
} else {
var count:Int = nums.get(charList(i)).get
count += 1
nums += (charList(i) -> count)
}
println(nums)
}
var result:String = ""
nums.keys.foreach{ c =>
result += nums(c) + "" + c
}
result
}
}
object AntProgressionTest extends App {
val app:AntProgression = new AntProgression
println(app.next("1"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment