Skip to content

Instantly share code, notes, and snippets.

@kazua
Last active December 15, 2015 11:39
Show Gist options
  • Save kazua/5255042 to your computer and use it in GitHub Desktop.
Save kazua/5255042 to your computer and use it in GitHub Desktop.
世界で闘うプログラマ本の1-5
//write Kazua
object worldproblem1_5 {
def ZipStr(tgt : String, zip : String = "", acl : String = "", bktgt : String = "") : String = tgt match {
case t if t.size == 0 => acl + zip.take(1) + zip.length
case t => acl match {
case a if a.length > 0 && a.length >= bktgt.length => bktgt
case a => zip match {
case z if z == "" => ZipStr(t.tail, z + t.head, a, t)
case z if z.head == t.head => ZipStr(t.tail, z + t.head, a, bktgt)
case z => ZipStr(t.tail, t.head.toString, a + z.head + z.length, bktgt)
}
}
}
def main(args : Array[String]) {
println(ZipStr("aabccccaaa"))
println(ZipStr("ddrrrtthhhhggf"))
println(ZipStr("abcdefg"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment