-
Notifications
You must be signed in to change notification settings - Fork 68
/
ScoobyDoo.rb
151 lines (126 loc) · 4.34 KB
/
ScoobyDoo.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
=begin
Description:
Good one Shaggy! We all love to watch Scooby Doo, Shaggy Rogers, Fred Jones,
Daphne Blake and Velma Dinkley solve the clues and figure out who was the villian.
The story plot rarely differed from one episode to the next. Scooby and his team
followed the clue then unmasked the villian at the end.
Scooby Doo
Your task is to initially solve the clues and then use those clues to unmask the
villian. You will be given a string of letters that you must manipulate in a way
that the clues guide you. You must then output the villian.
You will be given an Array of potential bad guys and you must only return the
correct masked villain.
Potential Villians
------------------
Black Knights
Puppet Master
Ghost Clowner
Witch Doctors
Waxed Phantom
Manor Phantom
Ghost Bigfoot
Haunted Horse
Davy Crockett
Captain Injun
Greens Gloobs
Ghostly Manor
Netty Crabbes
King Katazuma
Gators Ghouls
Headless Jack
Mambas Wambas
Medicines Man
Demon Sharker
Kelpy Monster
Gramps Vamper
Phantom Racer
Skeletons Men
Moon Monsters
Clue 1: The first clue is in a 'house' on 'String Class' Avenue.
Good luck!
=end
# Preloaded data
# class String
# def house
# "Step 1: Rotate all letters to the right by 5\nClue: You are close to the monster so you may need to create a 'Disguise'"
# end
# end
#
# class Disguise
# def initialize
# puts "Step 2: Reverse the whole string\nClue: What is the length of Scooby Doo's favourite snack?\nTry using the Integer Array"
# end
# end
#
# class Integer
# def eleven
# "Step 3: Add 5 letters onto every even letter in the Villans Name ie a=>f\nMake sure after the letter z it goes round to a"
# end
# end
#
# villians = ["Black Knights","Puppet Master","Ghost Clowner","Witch Doctors","Waxed Phantom","Manor Phantom","Ghost Bigfoot","Haunted Horse","Davy Crockett","Captain Injun","Greens Gloobs",
# "Ghostly Manor","Netty Crabbes","King Katazuma","Gators Ghouls","Headless Jack","Mambas Wambas","Medicines Man","Demon Sharker","Kelpy Monster","Gramps Vamper","Phantom Racer","Skeletons Men","Moon Monsters"]
# My Solution
def scoobydoo(villian, villians)
villian = villian.to_s.split(" ").join("").downcase
# Step 1 - Rotate Right by 5
villian = villian.split("").rotate(-5).join
# Step 2 - Reverse
villian.reverse!
# Step 3 - Change even letters by 5
badguy = ""
villian.split("").each_with_index.map {|z,i| badguy += i.odd? ? z.tr!("abcdefghijklmnopqrstuvwxyz","fghijklmnopqrstuvwxyzabcde") : z}
villians.each do |z|
return z if z.to_s.split(" ").join.downcase == badguy
end
end
# Solution to make the mask names
def scoobydooreverse(villian)
villian = villian.split(" ").join.downcase
# Step 3 - Change even letters by 5
badguy = ""
villian.split("").each_with_index.map {|z,i| badguy += i.odd? ? z.tr!("abcdefghijklmnopqrstuvwxyz","vwxyzabcdefghijklmnopqrstu") : z}
villian = badguy
# Step 2 - Reverse
villian.reverse!
# Step 1 - Rotate Right by 5
villian = villian.split("").rotate(5).join
villian
end
=begin
Random tests for codewars
villians = ["Black Knights","Puppet Master","Ghost Clowner","Witch Doctors",
"Waxed Phantom","Manor Phantom","Ghost Bigfoot","Haunted Horse","Davy Crockett",
"Captain Injun","Greens Gloobs","Ghostly Manor","Netty Crabbes","King Katazuma",
"Gators Ghouls","Headless Jack","Mambas Wambas","Medicines Man","Demon Sharker",
"Kelpy Monster","Gramps Vamper","Phantom Racer","Skeletons Men","Moon Monsters"]
mask = ["nfkxagbntcgd","moekpppmeosv","lxtnocgmeiwj","oyhxtdwnrjtx","hkdzxvwhoonv",
"hkrjnvmhoonv","iwtnocgoojfb","dztiuvhzsmoc","omctvvdotzkx","ndaopvciuend",
"gnnzemgnbjog","ygtnocgmoiah","rxyotznnewbv","tvkbndkvmpzv","gnrjtvgnlpoc",
"szlyazhfcvjn","wnawmvmnawmv","ndcddzmiahsz","hnnjmzdmefrv","ohyklzkmeosi",
"vnphamgmekmv","mjtiacpmexam","ooegefsiehsi","njmiojmnrztn"]
# Random Tests
(0..99).each do |rtest|
b = rand(villians.length)
Test.it("should work for random tests") do
Test.assert_equals(scoobydoo(mask[b],villians), villians[b])
end
end
letters = "abcdefghijklmnopqrstuvwxwz".split("")
(0..0).each do |rtest|
solution = []
n = rand(20) + 1
(0..20).each do |v|
word = ""
(0..n).each do |l|
b = rand(letters.length)
word << letters[b]
end
solution << word
end
start = scoobydooreverse(solution[0])
Test.it("should work for random tests") do
Test.assert_equals(scoobydoo(start,solution), solution[0])
end
end
=end