Skip to content

encode function#7

Open
sashazykov wants to merge 1 commit intohh-ex:masterfrom
sashazykov:feature/encoding
Open

encode function#7
sashazykov wants to merge 1 commit intohh-ex:masterfrom
sashazykov:feature/encoding

Conversation

@sashazykov
Copy link
Copy Markdown

No description provided.

@sashazykov
Copy link
Copy Markdown
Author

Ruby:

def compress(string)
  return "" if string.empty?
  _, head, tail = /(#{string[0]}+)(.*)/.match(string).to_a
  if head.size == 1
    "#{head}#{compress(tail)}"
  else
    "#{head.size}#{string[0]}#{compress(tail)}"
  end
end

compress("AAABBCCCCDEF")```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant