-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedup.rb
More file actions
27 lines (25 loc) · 784 Bytes
/
dedup.rb
File metadata and controls
27 lines (25 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#1. Dedupe
#
# Redundancy in this world is pointless. Let’s get rid of all redundancy.
# For example AAABB is redundant. Why not just use AB? Given a string, remove all consecutive letters that are same.
#
# Input: The first line in the data file is an integer that represents the number of data sets to follow.
# Each data set is a single string. The length of the string is less than 100. Each string only contains uppercase alphabetical letters.
#
# Output: Print the deduped strings.
#
# Sample Input File:
# 3
# ABBBBAACC
# AAAAA
# ABC
# Sample Output:
# ABAC
# A
# ABC
module Dedup
def self.filter(str)
selected_char = nil
str.chars.reject{|x| x == selected_char ? (selected_char = x; true) : (selected_char = x; false) }.join()
end
end