This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [0, 1, 2, 3, 5, 6] | |
n = 0 | |
n += 1 until arr[n] != n | |
puts n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [0, 1, 2, 3, 5, 6] | |
puts Array(0..arr.size) - arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(s) | |
s.gsub('B', '').gsub('AA', 'A').gsub('CC', 'C') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(a) | |
dup_elem_grouped = a.group_by { |e| e }.find { |k, v| v.size > 1 } | |
return 1 unless dup_elem_grouped | |
pos_start = a[a.index(dup_elem_grouped.first)] | |
pos_current = a[pos_start] | |
circle_size = 1 | |
until pos_start == pos_current | |
pos_current = a[pos_current] | |
circle_size += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require_relative 'anagram_solver' | |
describe AnagramSolver do | |
let(:dict) do | |
File.readlines('enable1.txt') | |
end | |
let(:anagram_solver) do | |
AnagramSolver.new(dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnagramSolver | |
def initialize(_dict) | |
@dict = File.readlines('enable1.txt').sort_by(&:size).reverse | |
end | |
def anagrams(data) | |
lines = data.split("\n") | |
lines_count = lines.delete_at(0) | |
Array.new(lines_count.to_i) do |line_number| | |
line = lines[line_number].downcase.gsub(/\W+/, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'anagram_solver' | |
start = Time.now | |
dict = File.readlines('enable1.txt') | |
anagram_solver = AnagramSolver.new(dict) | |
input = '6 | |
Desperate | |
Redditor | |
Dailyprogrammer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require_relative 'anagram_solver' | |
describe AnagramSolver do | |
let(:anagram_solver) do | |
AnagramSolver.new | |
end | |
describe '#anagrams' do | |
it do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnagramSolver | |
def initialize | |
@dict = File.readlines('enable1.txt').sort_by(&:size).reverse | |
end | |
def anagrams(data) | |
lines = data.split("\n") | |
lines_count = lines.delete_at(0) | |
Array.new(lines_count.to_i) do |line_number| | |
line = lines[line_number].downcase.gsub(/\W+/, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'anagram_solver' | |
start = Time.now | |
anagram_solver = AnagramSolver.new | |
input = '6 | |
Desperate | |
Redditor | |
Dailyprogrammer | |
Sam likes to swim |