Skip to content

Instantly share code, notes, and snippets.

Bruno Maia queimadus

Block or report user

Report or block queimadus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@queimadus
queimadus / encoder.scala
Created Feb 29, 2020
Chuck Norris Unary Code Binary Encoder
View encoder.scala
def encodeBinaryString(s: String) = {
s.foldLeft(List.empty[List[Char]]) {
case (List(), cur) => List(List(cur))
case ((head @ h :: _) :: tail, cur) if cur == h => (cur :: head) :: tail
case (acc, cur) => List(cur) :: acc
}.map {
case l @ '1' :: _ => "0 " + "0" * l.size
case l @ '0' :: _ => "00 " + "0" * l.size
}.mkString(" ")
}
You can’t perform that action at this time.