-
Notifications
You must be signed in to change notification settings - Fork 0
/
2016-gem-stones.rb
55 lines (53 loc) · 1.32 KB
/
2016-gem-stones.rb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Gemstones by darkshadows
# https://www.hackerrank.com/challenges/gem-stones
#
# John has discovered various rocks. Each rock is composed of various elements,
# and each element is represented by a lower-case Latin letter from 'a' to 'z'.
# An element can be present multiple times in a rock. An element is called a
# gem-element if it occurs at least once in each of the rocks.
#
# Given the list of rocks with their compositions, display the number of
# gem-elements that exist in those rocks.
#
# Input Format
#
# The first line consists of an integer, , the number of rocks. Each of the next
# lines contains a rock's composition. Each composition consists of lower-case
# letters of English alphabet.
#
# Constraints
#
# Each composition consists of only lower-case Latin letters ('a'-'z'). length of
# each composition
#
# Output Format
#
# Print the number of gem-elements that are common in these rocks. If there are
# none, print 0.
#
# Sample Input:
#
# abcdde
# baccd
# eeabg
#
# Sample Output:
#
# 2
#
# Explanation
#
# Only "a" and "b" are the two kinds of gem-elements, since these are the only
# characters that occur in every rock's composition.
input =<<INPUT
Lorem ipsum
dolor sit amet,
consectetur,
adipisci velit
INPUT
p input.
each_line.
map(&:strip).
select { |l| l =~ /[a-z]/ }.
map(&:chars).
reduce(&:&).count