forked from CoderAcademy-BRI/ruby-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14_hackerman.rb
More file actions
60 lines (35 loc) · 1.64 KB
/
14_hackerman.rb
File metadata and controls
60 lines (35 loc) · 1.64 KB
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
56
57
58
59
60
# You have to stop the infamous hackerman by writing a basic security program.
# Your task is to write a program which will ask the user for input twice.
# Both times should ask the user to type words and will display the FIRST input.
# However if any of the words in the second input match with a word from the
# first input it should say "HIDDEN" instead of the matched word.
# Example:
# first_input = bob rob dob mob
# second_input = kob fob dob
# output = bob rob HIDDEN mob
# Check your solution by running:
# ruby 14_hackerman.rb
puts "type words to enter program" #ask user first question
answer1 = gets.chomp.downcase.split(" ") #get users first answer and split into array of strings
puts answer1
puts "type words to enter program" #ask user second question
answer2 = gets.chomp.downcase.split(" ") #get users second answer in downcase and split into an array of string
# answer1 = [] creates an array of strings
# answer2 = [] creates an array of strings
new_array = []
puts new_array << answer1.zip(answer2).map { |x, y| x == y }
new_array.each |item|
if item == true
puts answer1[i]
else
puts "HIDDEN"
end
#answer 1 ["string", "string"]
#answer 2 ["string", string]
#check all elements in first string against all elements in second string
#if not equal to elements in second string print element of first string
#if equal to element in second string print HIDDEN
# Your code here
# Beast mode:
# Does your code deal with capital letters? Update your solution so that
# they will be downsized if they are input but HIDDEN remains capitalised.