algoritmos 0.1.0 → 0.1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e02b164734968b683906a2ae704c01ae1fca740e27c6d7c123ba408864215ea3
4
- data.tar.gz: ae880551510a7d07356440d77e7011dc08767d86eda0edeed9a59fe6d090c172
3
+ metadata.gz: 0d533bb50409a4a99568a1510bcbcd6062ebec99afb3485ae273b69d93856723
4
+ data.tar.gz: 0a3c82a789a463924925fe8d7cbb582956f15d981615ab045fb83058fae3985b
5
5
  SHA512:
6
- metadata.gz: 34ad428368223ec1a799084225338521c201ba249e7e022abaf40ee32a888a4d56dddda2441563e2a22a10ade55a9297707b8411986224cc12e80d05b6ef5ebd
7
- data.tar.gz: 16780f069c0aec7f59e0a8ab7e155437650be60cf5a34da880178bb488f13be14e8a23089e134b16a4bcf884b460c10e1c9015ed96399bb2c1612aa9b966b79a
6
+ metadata.gz: 10d394c40a0f4dedafbf01bce74ba8e47a6b012450b04b09c998c6d59489f462d68042ee95227629816c6d4e7ed5dd0c8daa69d0ae473c3ece5abfe724911d05
7
+ data.tar.gz: a490bd38eda5ca67337e45b0aecfb785be1c40eaeb3911ab721ad44dbb10448a039c19d20bf7a386afc9befc3156aacb5521f25541ce837a3c6c9fe623a183bf
data/lib/algoritmos.rb CHANGED
@@ -1,8 +1,35 @@
1
- # frozen_string_literal: true
1
+ array = [2,5,8,12,16,23,38,56,72,91] # Array de números
2
+ key = 16 # Elemento a ser encontrado
2
3
 
3
- require_relative "algoritmos/version"
4
+ # Primeiro passo
5
+ # Retornar a metade de um array
4
6
 
5
- module Algoritmos
6
- class Error < StandardError; end
7
- # Your code goes here...
7
+ def split_array(array, key, start_index, end_index)
8
+ # Receber um array, Dividi-lo e retornar a parte conveniente
9
+
10
+ return -1 if start_index > end_index
11
+ #sizeArray = array.length # Pegar o comprimento total
12
+ #halfIndex = (sizeArray / 2) - 1 # Temos aqui o índice do elemento do meio
13
+ half_index = (start_index + end_index) / 2
14
+ if array[half_index] == key
15
+ return half_index
16
+ elsif key < array[half_index]
17
+ split_array(array, key, start_index, half_index - 1)
18
+ else
19
+ split_array(array, key, half_index + 1, end_index)
20
+ end
21
+ end
22
+
23
+ def binarySearch(array, key)
24
+ split_array(array,key,0,array.length - 1)
8
25
  end
26
+
27
+ index = binarySearch(array,key)
28
+
29
+ puts index
30
+
31
+ if index == -1
32
+ puts "Não encontrado"
33
+ else
34
+ puts "Elemento encontrado no índice #{index}"
35
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoritmos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Brito de Lima
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
@@ -17,25 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".rspec"
21
- - ".rubocop.yml"
22
- - CHANGELOG.md
23
- - CODE_OF_CONDUCT.md
24
- - LICENSE.txt
25
- - README.md
26
- - Rakefile
27
- - lib/BinarySearch.rb
28
- - lib/BubbleSort.rb
29
- - lib/CountingSort.rb
30
- - lib/HelloWorld.rb
31
- - lib/LinearSearch.rb
32
- - lib/MaximizeArray.rb
33
- - lib/MinimumSpanningTree.rb
34
- - lib/MinimumSum.rb
35
- - lib/MissingChacter.rb
36
20
  - lib/algoritmos.rb
37
- - lib/algoritmos/version.rb
38
- - sig/algoritmos.rbs
39
21
  homepage:
40
22
  licenses:
41
23
  - MIT
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,13 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2023-08-09
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at lucasbritocientista@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 Lucas Brito de Lima
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,39 +0,0 @@
1
- # Algoritmos
2
-
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/algoritmos`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/algoritmos. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/algoritmos/blob/master/CODE_OF_CONDUCT.md).
32
-
33
- ## License
34
-
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the Algoritmos project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/algoritmos/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
data/lib/BinarySearch.rb DELETED
@@ -1,35 +0,0 @@
1
- array = [2,5,8,12,16,23,38,56,72,91] # Array de números
2
- key = 16 # Elemento a ser encontrado
3
-
4
- # Primeiro passo
5
- # Retornar a metade de um array
6
-
7
- def split_array(array, key, start_index, end_index)
8
- # Receber um array, Dividi-lo e retornar a parte conveniente
9
-
10
- return -1 if start_index > end_index
11
- #sizeArray = array.length # Pegar o comprimento total
12
- #halfIndex = (sizeArray / 2) - 1 # Temos aqui o índice do elemento do meio
13
- half_index = (start_index + end_index) / 2
14
- if array[half_index] == key
15
- return half_index
16
- elsif key < array[half_index]
17
- split_array(array, key, start_index, half_index - 1)
18
- else
19
- split_array(array, key, half_index + 1, end_index)
20
- end
21
- end
22
-
23
- def binarySearch(array, key)
24
- split_array(array,key,0,array.length - 1)
25
- end
26
-
27
- index = binarySearch(array,key)
28
-
29
- puts index
30
-
31
- if index == -1
32
- puts "Não encontrado"
33
- else
34
- puts "Elemento encontrado no índice #{index}"
35
- end
data/lib/BubbleSort.rb DELETED
@@ -1,23 +0,0 @@
1
- puts "Bubble Sort"
2
- puts "-----------------"
3
- lista = [18, 7, 55, 23, 1, 12, 57, 85, 42]
4
-
5
- def BubbleSort(lista)
6
- n = lista.length
7
- troca = true
8
-
9
- while troca
10
- troca = false
11
- for i in 0..n-2
12
- if lista[i] > lista[i + 1]
13
- lista[i], lista[i + 1] = lista[i + 1], lista[i]
14
- troca = true
15
- end
16
- end
17
- n -= 1
18
- end
19
-
20
- puts lista
21
- end
22
-
23
- BubbleSort(lista)
data/lib/CountingSort.rb DELETED
@@ -1,40 +0,0 @@
1
- # Algoritmo de Counting Sort em Ruby
2
- def counting_sort(array)
3
- # Etapa 1: Encontrar o valor máximo e mínimo do array
4
- max_val = array[0]
5
- min_val = array[0]
6
-
7
- array.each do |num|
8
- max_val = num if num > max_val
9
- min_val = num if num < min_val
10
- end
11
-
12
- # Etapa 2: Criar o array de contagem
13
- range = max_val - min_val + 1
14
- count_arr = Array.new(range, 0)
15
-
16
- # Etapa 3: Contar as ocorrências dos elementos
17
- array.each do |num|
18
- count_arr[num - min_val] += 1
19
- end
20
-
21
- # Etapa 4: Calcular as posições finais no array ordenado
22
- (1...range).each do |i|
23
- count_arr[i] += count_arr[i - 1]
24
- end
25
-
26
- # Etapa 5: Construir a lista ordenada
27
- sorted_arr = Array.new(array.length)
28
- array.reverse_each do |num|
29
- sorted_arr[count_arr[num - min_val] - 1] = num
30
- count_arr[num - min_val] -= 1
31
- end
32
-
33
- return sorted_arr
34
- end
35
-
36
- # Teste com um array de exemplo
37
- array = [8,8,2,3,2,4,6,8,6,7,2,3,5,7,9]
38
- puts "Array original: #{array}"
39
- sorted_arr = counting_sort(array)
40
- puts "Array ordenado: #{sorted_arr.join(', ')}"
data/lib/HelloWorld.rb DELETED
@@ -1,11 +0,0 @@
1
- class HelloWorld
2
- def sayHello
3
- puts "Hello World"
4
- end
5
-
6
- def self.digaOi
7
- puts "Olá Mundo!"
8
- end
9
- end
10
-
11
- HelloWorld.digaOi
data/lib/LinearSearch.rb DELETED
@@ -1,18 +0,0 @@
1
- puts "Linear Search"
2
- puts "-------------"
3
-
4
- def findIndexAndNumber(number, array)
5
- i = 0 # Inicializador do array
6
- size = array.length
7
- while i < size do
8
- if array[i] == number then
9
- puts "Number #{number} founded at #{i} of array"
10
- return
11
- end
12
- i = i + 1
13
- end
14
-
15
- puts "Number not found!"
16
- end
17
-
18
- findIndexAndNumber(56, [22,32,12,44,56])
data/lib/MaximizeArray.rb DELETED
@@ -1,26 +0,0 @@
1
- def maximize_array(array, k)
2
- # Ordenar o array do menor ao maior
3
- sort_array = array.sort
4
- sum = 0
5
- i = 0
6
-
7
- while k > 0
8
- if (sort_array[i] >= 0)
9
- k = 0
10
- else
11
- sort_array[i] = (-1) * sort_array[i]
12
- k -= 1
13
- end
14
- i += 1
15
- end
16
-
17
- sort_array.each do |j|
18
- sum += j
19
- end
20
-
21
- return sum
22
-
23
- end
24
-
25
- array = [-2,0,5,-1,2]
26
- puts maximize_array(array,4)
@@ -1,80 +0,0 @@
1
- # Implementação da estrutura de dados Union-Find
2
- class UnionFind
3
- def initialize(size)
4
- @parent = Array.new(size, -1)
5
- end
6
-
7
- def find(x)
8
- x_root = x
9
- x_root = @parent[x_root] while @parent[x_root] >= 0
10
- while x != x_root
11
- new_parent = @parent[x]
12
- @parent[x] = x_root
13
- x = new_parent
14
- end
15
- x_root
16
- end
17
-
18
- def union(x, y)
19
- x_root = find(x)
20
- y_root = find(y)
21
- return if x_root == y_root
22
-
23
- if @parent[x_root] <= @parent[y_root]
24
- @parent[x_root] += @parent[y_root]
25
- @parent[y_root] = x_root
26
- else
27
- @parent[y_root] += @parent[x_root]
28
- @parent[x_root] = y_root
29
- end
30
- end
31
- end
32
-
33
- # Implementação do algoritmo de Kruskal
34
- def kruskal(graph)
35
- edges = graph.edges.sort_by { |edge| edge[2] } # Ordenar as arestas pelo peso (custo)
36
- num_vertices = graph.num_vertices
37
- mst = [] # Lista para armazenar as arestas da MST
38
-
39
- union_find = UnionFind.new(num_vertices)
40
-
41
- edges.each do |edge|
42
- u, v, weight = edge
43
- if union_find.find(u) != union_find.find(v)
44
- mst << edge
45
- union_find.union(u, v)
46
- end
47
- end
48
-
49
- mst
50
- end
51
-
52
- class Graph
53
- attr_reader :edges, :num_vertices
54
-
55
- def initialize(num_vertices)
56
- @edges = []
57
- @num_vertices = num_vertices
58
- end
59
-
60
- def add_edge(u, v, weight)
61
- @edges << [u, v, weight]
62
- end
63
- end
64
-
65
- # Criando o grafo de exemplo
66
- graph = Graph.new(6)
67
- graph.add_edge(0, 1, 4)
68
- graph.add_edge(0, 2, 3)
69
- graph.add_edge(1, 2, 1)
70
- graph.add_edge(1, 3, 2)
71
- graph.add_edge(2, 3, 4)
72
- graph.add_edge(3, 4, 2)
73
- graph.add_edge(4, 5, 6)
74
-
75
- # Executando o algoritmo de Kruskal
76
- mst = kruskal(graph)
77
-
78
- # Exibindo a MST
79
- puts "Minimum Spanning Tree:"
80
- mst.each { |edge| puts "#{edge[0]} -- #{edge[1]} (weight: #{edge[2]})" }
data/lib/MinimumSum.rb DELETED
@@ -1,8 +0,0 @@
1
- def min_sum(array, number)
2
- min_val = array.min
3
- return (min_val * (number - 1))
4
- end
5
-
6
- array = [23, 56, 12, 63, 8]
7
- number = array.count
8
- puts min_sum(array, number)
@@ -1,30 +0,0 @@
1
- require 'set'
2
-
3
- def missing_character(phrase = 0)
4
- alphabet = ('a'..'z').to_a
5
- downcase_string = phrase.downcase
6
- phrase_sanitize = downcase_string.gsub(/[\s,\.]/, '')
7
- array_letter = phrase_sanitize.chars
8
-
9
- # Criando um conjunto com todas as letras do alfabeto
10
- alphabet_set = Set.new(alphabet)
11
-
12
- # Removendo as letras da frase do conjunto
13
- array_letter.each do |letter|
14
- alphabet_set.delete(letter)
15
- end
16
-
17
- # Convertendo o conjunto de letras ausentes para um array
18
- letters_missing = alphabet_set.to_a
19
-
20
- # Exibindo as letras ausentes em um puts
21
- puts "Letras ausentes na frase:"
22
- puts letters_missing.join(', ')
23
-
24
- # Retorna a quantidade de letras ausentes
25
- return letters_missing.size
26
-
27
- end
28
-
29
- ok = missing_character("Eu sou o melhor dos mundos")
30
- puts "Quantidade de letras ausentes: #{ok}"
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Algoritmos
4
- VERSION = "0.1.0"
5
- end
data/sig/algoritmos.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Algoritmos
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end