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 'base' | |
describe Base do | |
describe '#smallest' do | |
it do | |
expect(subject.smallest('1')).to eq('base 2 => 1') | |
end | |
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 Base | |
def smallest(num) | |
"base #{smallest_base(num)} => #{to_dec(num, smallest_base(num))}" | |
end | |
def all_bases(num) | |
(smallest_base(num).to_i..16).map { |base| "base #{base} => #{to_dec(num, base)}" }.join("\n") | |
end | |
def to_dec(num, base) |
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 |
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 '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
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
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 '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
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
def solution(s) | |
s.gsub('B', '').gsub('AA', 'A').gsub('CC', 'C') | |
end |