Skip to content

Commit f261b45

Browse files
committed
Inserido algoritmo de palindromo em ruby e modificaçao do README.
1 parent 1dc44d9 commit f261b45

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
6969
|-------------------------------------|-------|------|--------|----|------|------------|--------|
7070
| Lista com 2 Pilhas | C/C++ | Java | [Python](/src/python/lista_com_pilhas.py) | Go | Ruby | Javascript | Pascal |
7171
| Problema da Soma de 2 Números | C/C++ | Java | [Python](/src/python/soma_dois_numeros.py) | Go | Ruby | Javascript | Pascal |
72-
| [Palíndromo][49] | [C/C++](/src/c/Palindromo.c) | Java | Python | Go | Ruby | Javascript | Pascal |
72+
| [Palíndromo][49] | [C/C++](/src/c/Palindromo.c) | Java | Python | Go | [Ruby](/src/ruby/Palindromo.rb) | Javascript | Pascal |
7373
| Lista Encadeada Desordenada | C/C++ | Java | [Python](/src/python/lista_encadeada_desordenada.py) | Go | Ruby | Javascript | Pascal |
7474
| [Calcula o PI (Fórmula de Leibniz)][50] | C/C++ | Java | [Python](/src/python/calculate_pi.py) | Go | Ruby | Javascript | Pascal |
7575
| Busca em Labirinto | C/C++ | Java | [Python](/src/python/busca_em_labirinto.py) | Go | Ruby | Javascript | Pascal |

src/ruby/Palindromo.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "test/unit/assertions"
2+
include Test::Unit::Assertions
3+
4+
#the easiest implementation would be using .reverse method
5+
6+
7+
def is_palindrome(string)
8+
9+
return true if string.size == 1 || string.size == 0
10+
11+
reversed = ""
12+
string = string.gsub(" ", "").downcase
13+
string.chars.reverse_each do |c|
14+
reversed << c
15+
end
16+
17+
reversed == string ? true : false
18+
end
19+
20+
assert_equal is_palindrome("abba"), true
21+
assert_equal is_palindrome("abbas"), false
22+
assert_equal is_palindrome("tattarrattat"), true
23+
assert_equal is_palindrome("Was it a palindrome?"), false
24+
assert_equal is_palindrome("No lemon, no melon"), true

0 commit comments

Comments
 (0)