Skip to content

Commit 640ab25

Browse files
committed
Fix some ruby files using rubocop
1 parent 7197332 commit 640ab25

10 files changed

+36
-46
lines changed

src/ruby/Fatorial.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/ruby/Hanoi.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3-
def Hanoi(pin0, pin2, pin1, num)
3+
def hanoi(pin0, pin2, pin1, num)
44
if num == 1
55
# Show the operations
66
print 'Move from ', pin0, ' to ', pin2, "\n"
77
else
8-
Hanoi(pin0, pin1, pin2, num - 1)
9-
Hanoi(pin0, pin2, pin1, 1)
10-
Hanoi(pin1, pin2, pin0, num - 1)
8+
hanoi(pin0, pin1, pin2, num - 1)
9+
hanoi(pin0, pin2, pin1, 1)
10+
hanoi(pin1, pin2, pin0, num - 1)
1111
end
1212
end
1313

1414
# Move from Pin-0 to Pin-2 using Pin-1 as helper (number of disks = 3)
15-
Hanoi(0, 2, 1, 3)
15+
hanoi(0, 2, 1, 3)

src/ruby/Lista_duplamente_encadeada.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Class to represent each node from the linked list
34
class Node
45
attr_accessor :data, :next, :previous
56

@@ -10,6 +11,7 @@ def initialize(data)
1011
end
1112
end
1213

14+
# Implement a doubly linked list
1315
class DoublyLinkedList
1416
def initialize
1517
@head = nil

src/ruby/Lista_encadeada.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Class that represents each node from the linked list
34
class Node
45
attr_accessor :data, :next
56

@@ -9,6 +10,7 @@ def initialize(data)
910
end
1011
end
1112

13+
# Implement the linked list data structure
1214
class LinkedList
1315
def initialize
1416
@head = nil

src/ruby/busca_sequencial.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,5 @@ def busca_sequencial(valor, vetor)
99
-1
1010
end
1111

12-
# Teste Manual
1312
vetor = [1, 4, 5, 2, 42, 34, 54, 98, 89, 78, 67]
1413
puts busca_sequencial(98, vetor)
15-
16-
# Teste Automatizado
17-
require 'minitest/autorun'
18-
19-
class Test < Minitest::Test
20-
def test_busca_sequencial_quando_nao_encontra_o_valor
21-
assert_equal busca_sequencial(5, []), -1
22-
end
23-
24-
def test_busca_sequencial_quando_encontra_os_valores
25-
vetor = [1, 4, 5, 2, 42, 34, 54, 98, 89, 78, 67]
26-
vetor.each_with_index do |elemento, indice|
27-
assert_equal busca_sequencial(elemento, vetor), indice
28-
end
29-
end
30-
end

src/ruby/deque.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Carlos Alves
55
# https://github.com/EuCarlos
66

7+
# Implement Deque data structure
78
class Deque
89
attr_accessor :deque
910

src/ruby/fatorial.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
def fatorial(number)
4+
aux = 1
5+
(2..number).each do |x|
6+
aux *= x
7+
end
8+
aux
9+
end
10+
11+
def fatorial_recursiva(number)
12+
return 1 if number <= 1
13+
14+
n * fatorial_recursiva(number - 1)
15+
end
16+
17+
puts fatorial(5)
18+
puts fatorial_recursiva(5)

src/ruby/Fibonacci.rb renamed to src/ruby/fibonacci.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# frozen_string_literal: true
22

3-
def fibonacci(n)
3+
def fibonacci(number)
44
last = 0
55
curr = 1
6-
(0..n - 1).each do |_|
6+
(0..number - 1).each do |_|
77
swap = curr
88
curr += last
99
last = swap
1010
end
1111
last
1212
end
1313

14-
def fibonacci_recursiva(n)
15-
if n <= 0
14+
def fibonacci_recursiva(number)
15+
if number <= 0
1616
0
17-
elsif n == 1
17+
elsif number == 1
1818
1
1919
else
20-
fibonacci(n - 1) + fibonacci(n - 2)
20+
fibonacci(number - 1) + fibonacci(number - 2)
2121
end
2222
end
2323

src/ruby/Fila.rb renamed to src/ruby/fila.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Implements a Queue data structure
34
class Queue
45
def initialize
56
@queue = []

src/ruby/Pilha.rb renamed to src/ruby/pilha.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
# Implement the Stack data structure
34
class Stack
45
def initialize
56
@stack = []

0 commit comments

Comments
 (0)