Created
September 6, 2012 04:22
-
-
Save keesun/3651199 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
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