{"id":3016,"date":"2012-10-21T04:26:38","date_gmt":"2012-10-20T19:26:38","guid":{"rendered":"http:\/\/blog.tksk.net\/?p=3016"},"modified":"2012-10-21T07:33:34","modified_gmt":"2012-10-20T22:33:34","slug":"run-length-encoding","status":"publish","type":"post","link":"https:\/\/blog.tksk.net\/?p=3016","title":{"rendered":"run length encoding"},"content":{"rendered":"<p>run length encoding \u3063\u3066\u3001\u624b\u7d9a\u578b\u3067\u66f8\u304f\u306e\u9762\u5012\u3060\u3088\u306d\u3002\u3068\u3044\u3046\u304b\u3001\u624b\u7d9a\u578b\u3067\u66f8\u304f\u3053\u3068\u8003\u3048\u308b\u306e\u9762\u5012\u304f\u3055\u304f\u3066\u3044\u3084\u3060\u3088\u3002<\/p>\n<p>Scala\u3061\u3083\u3093\u3067\u89e3\u3044\u3066\u307f\u308b\u3002<br \/>\n<code><br \/>\nscala&gt; def runlength[T](list: List[T]): List[(T, Int)] = list match {<br \/>\n|\u00a0\u00a0 case Nil =&gt; Nil<br \/>\n|\u00a0\u00a0 case x :: xs =&gt; val (first, rest) = xs.span(x ==)<br \/>\n|\u00a0\u00a0\u00a0\u00a0 (x, first.length+1) :: runlength(rest)<br \/>\n| }<br \/>\nrunlength: [T](list: List[T])List[(T, Int)]<br \/>\nscala&gt; runlength(\"aaabbabbbdccbabaaabab\".toList)<br \/>\nres11: List[(Char, Int)] = List((a,3), (b,2), (a,1), (b,3), (d,1), (c,2), (b,1), (a,1), (b,1), (a,3), (b,1), (a,1), (b,1))<br \/>\n<\/code><\/p>\n<p>\u3084\u3063\u305f\u30014\u884c\u3067\u66f8\u3051\u3061\u3083\u3063\u305f\u3002\u4ed5\u65b9\u306a\u3044\u306e\u3067(\u4f55\u304c?)\u3001<a href=\"https:\/\/gist.github.com\/e96451d08e686ccfbb95#file_run_length.java\">\u7cde\u307f\u305f\u3044\u306a\u30b3\u30fc\u30c9\u3082\u66f8\u3044\u3066\u307f\u305f\u3002<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>run length encoding \u3063\u3066\u3001\u624b\u7d9a\u578b\u3067\u66f8\u304f\u306e\u9762\u5012\u3060\u3088\u306d\u3002\u3068\u3044\u3046\u304b\u3001\u624b\u7d9a\u578b\u3067\u66f8\u304f\u3053\u3068\u8003\u3048\u308b\u306e\u9762\u5012\u304f\u3055\u304f\u3066\u3044\u3084\u3060\u3088\u3002 Scala\u3061\u3083\u3093\u3067\u89e3\u3044\u3066\u307f\u308b\u3002 scala&gt; def runlength[T](li [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/3016"}],"collection":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3016"}],"version-history":[{"count":9,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/3016\/revisions"}],"predecessor-version":[{"id":3026,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=\/wp\/v2\/posts\/3016\/revisions\/3026"}],"wp:attachment":[{"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tksk.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}