palindrome_algo 1.01 → 1.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -2
- data/Rakefile +4 -10
- data/lib/palindrome_algo.rb +5 -1
- data/lib/palindrome_algo/solver.rb +29 -5
- data/lib/palindrome_algo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '068026b4a64b46f307410e9d744246d07c6de398d8b6e0c19bc7cf5bef103174'
|
4
|
+
data.tar.gz: c7d937d233344f0f88949e51e8d2c70929817bebaa4460b2b78246421dfc01cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f11dc9ecd5de41a3f8638a1b73ea7a3c99e4be5f40d2f7cdf27bfc0dfade33d3e414511ba693439ef3620d05da875dddbeb27b33786732eea54c813de4ce2db
|
7
|
+
data.tar.gz: c70f89825a02b58398198d57176e0114c00ffd4da456c002637620e691d795e7d908bd4877955c823673463b992e427fe482d90b190e55ab2cc7bdd1f012764f
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
|
6
6
|
#### PalindromeAlgo is a simple algorithm to find and return list of palindromes from your text input.
|
7
7
|
|
8
|
-
Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
@@ -25,7 +24,47 @@ Or install it yourself as:
|
|
25
24
|
|
26
25
|
## Usage
|
27
26
|
|
28
|
-
|
27
|
+
1) Add your text to a hash with `:text` symbol key, then pass the arguments to `PalindromeAlgo.parse(args)` like the example below. If you don't pass any args, and just run `PalindromeAlgo.parse` it will return sample data for testing.
|
28
|
+
|
29
|
+
```
|
30
|
+
args = { text: "My best friend's name is Anna. Don't you love the civic opera? How much is a kayak? My Spanish level is low, but I have fun. Excuse me, Madam? Is this yours? Where's your mom today? Let's go for lunch at noon. Did you see that racecar? When was the radar invented? Your face is redder than a tomato. So we somehow refer cases to you? How much is it to repaper the living room? The rotator was connected to the log by a rope 6 ft. I heard the tail rotor buzz again. For later versions and adaptations of the sagas see O. His guitar solos are just unbelievable. As a doctor, Kent strongly believes the tenet of never doing any harm. Wow, you made this by yourself?" }
|
31
|
+
|
32
|
+
palindrome_hash = PalindromeAlgo.parse(args)
|
33
|
+
```
|
34
|
+
|
35
|
+
2) The returned data will be in hash format like below:
|
36
|
+
|
37
|
+
You can access the data, like so: `palindrome_hash[:results]` and `palindrome_hash[:text]`
|
38
|
+
|
39
|
+
```
|
40
|
+
{
|
41
|
+
:results=>
|
42
|
+
[
|
43
|
+
{:string=>"My best friend's name is Anna", :palindromes=>"anna"},
|
44
|
+
{:string=>"Don't you love the civic opera", :palindromes=>"civic"},
|
45
|
+
{:string=>"How much is a kayak", :palindromes=>"kayak"},
|
46
|
+
{:string=>"My Spanish level is low, but I have fun", :palindromes=>"level"},
|
47
|
+
{:string=>"Excuse me, Madam", :palindromes=>"madam"},
|
48
|
+
{:string=>"Is this yours", :palindromes=>""},
|
49
|
+
{:string=>"Where's your mom today", :palindromes=>"mom"},
|
50
|
+
{:string=>"Let's go for lunch at noon", :palindromes=>"noon"},
|
51
|
+
{:string=>"Did you see that racecar", :palindromes=>"did, racecar"},
|
52
|
+
{:string=>"When was the radar invented", :palindromes=>"radar"},
|
53
|
+
{:string=>"Your face is redder than a tomato", :palindromes=>"redder"},
|
54
|
+
{:string=>"So we somehow refer cases to you", :palindromes=>"refer"},
|
55
|
+
{:string=>"How much is it to repaper the living room", :palindromes=>"repaper"},
|
56
|
+
{:string=>"The rotator was connected to the log by a rope 6 ft", :palindromes=>"rotator"},
|
57
|
+
{:string=>"I heard the tail rotor buzz again", :palindromes=>"rotor"},
|
58
|
+
{:string=>"For later versions and adaptations of the sagas see O", :palindromes=>"sagas"},
|
59
|
+
{:string=>"His guitar solos are just unbelievable", :palindromes=>"solos"},
|
60
|
+
{:string=>"As a doctor, Kent strongly believes the tenet of never doing any harm", :palindromes=>"tenet"},
|
61
|
+
{:string=>"Wow, you made this by yourself", :palindromes=>"wow"}
|
62
|
+
],
|
63
|
+
:text=>
|
64
|
+
"My best friend's name is Anna. Don't you love the civic opera? How much is a kayak? My Spanish level is low, but I have fun. Excuse me, Madam? Is this yours? Where's your mom today? Let's go for lunch at noon. Did you see that racecar? When was the radar invented? Your face is redder than a tomato. So we somehow refer cases to you? How much is it to repaper the living room? The rotator was connected to the log by a rope 6 ft. I heard the tail rotor buzz again. For later versions and adaptations of the sagas see O. His guitar solos are just unbelievable. As a doctor, Kent strongly believes the tenet of never doing any harm. Wow, you made this by yourself?"
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
29
68
|
|
30
69
|
## Development
|
31
70
|
|
data/Rakefile
CHANGED
@@ -18,22 +18,16 @@ task :console do
|
|
18
18
|
require "active_support/all"
|
19
19
|
ARGV.clear
|
20
20
|
|
21
|
-
|
22
|
-
# binding.pry
|
21
|
+
palindrome_hash = run_palindrome
|
23
22
|
|
24
23
|
IRB.start
|
25
24
|
end
|
26
25
|
|
27
26
|
|
28
|
-
def
|
29
|
-
|
30
|
-
solve = PalindromeAlgo::Solver.new
|
31
|
-
res = solve.start
|
32
|
-
binding.pry
|
27
|
+
def run_palindrome
|
28
|
+
args = { text: "My best friend's name is Anna. Don't you love the civic opera? How much is a kayak? My Spanish level is low, but I have fun. Excuse me, Madam? Is this yours? Where's your mom today? Let's go for lunch at noon. Did you see that racecar? When was the radar invented? Your face is redder than a tomato. So we somehow refer cases to you? How much is it to repaper the living room? The rotator was connected to the log by a rope 6 ft. I heard the tail rotor buzz again. For later versions and adaptations of the sagas see O. His guitar solos are just unbelievable. As a doctor, Kent strongly believes the tenet of never doing any harm. Wow, you made this by yourself?" }
|
33
29
|
|
34
|
-
|
35
|
-
# scraped_links = scraper.start('https://en.wikipedia.org/wiki/Austin%2C_Texas')
|
36
|
-
# binding.pry
|
30
|
+
palindrome_hash = PalindromeAlgo.parse(args)
|
37
31
|
|
38
32
|
# scraper = LinkScraper::Scrape.new(WebsCriteria.all_scrub_web_criteria)
|
39
33
|
end
|
data/lib/palindrome_algo.rb
CHANGED
@@ -2,16 +2,40 @@
|
|
2
2
|
module PalindromeAlgo
|
3
3
|
class Solver
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
# AlgoService.new.run_palindrome({string: 'lemon apple madam cinema restful fluster'})
|
7
|
+
def run_palindrome(args = {})
|
8
|
+
string_block = args.fetch(:text, nil)
|
9
|
+
string_block = sample_string_block if !string_block.present?
|
10
|
+
parsed_strings = parse_string_block(string_block)
|
11
|
+
|
12
|
+
results = parsed_strings.map do |string|
|
13
|
+
{ string: string, palindromes: find_palindromes(string) }
|
14
|
+
end
|
15
|
+
|
16
|
+
palindrome_hash = { results: results, text: string_block }
|
7
17
|
end
|
8
18
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
19
|
+
def parse_string_block(string_block)
|
20
|
+
strings = string_block.split(/\.\s+|!|\?/)
|
21
|
+
strings = strings.map { |str| str.squeeze(' ') }
|
22
|
+
strings = strings.map(&:strip)
|
12
23
|
end
|
13
24
|
|
25
|
+
# # array = ['madam', 'restful', 'fluster']
|
26
|
+
def find_palindromes(word_string)
|
27
|
+
original_strs = word_string.downcase.split(/\W+/).sort
|
28
|
+
|
29
|
+
palindromes = original_strs.select do |str|
|
30
|
+
str == str.reverse if str.length > 1
|
31
|
+
end
|
14
32
|
|
33
|
+
palindromes = palindromes.sort.join(', ')
|
34
|
+
end
|
35
|
+
|
36
|
+
def sample_string_block
|
37
|
+
"My best friend's name is Anna. Don't you love the civic opera? How much is a kayak? My Spanish level is low, but I have fun. Excuse me, Madam? Is this yours? Where's your mom today? Let's go for lunch at noon. Did you see that racecar? When was the radar invented? Your face is redder than a tomato. So we somehow refer cases to you? How much is it to repaper the living room? The rotator was connected to the log by a rope 6 ft. I heard the tail rotor buzz again. For later versions and adaptations of the sagas see O. His guitar solos are just unbelievable. As a doctor, Kent strongly believes the tenet of never doing any harm. Wow, you made this by yourself?"
|
38
|
+
end
|
15
39
|
|
16
40
|
end
|
17
41
|
end
|