Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets - Tatiana #1

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

11 changes: 11 additions & 0 deletions 00-hello-world/hello_world.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# def hello_world name=''
# return name == '' ? "Hello, World!" : "Hello, #{name}!"
# end

# ruby optional positional argument name=''

# another way to do it:
def hello_world name=''
name = 'World' if name == ''
return "Hello, #{name}!"
end
2 changes: 1 addition & 1 deletion 00-hello-world/hello_world_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
it "When given an empty string it should greet the world!" do
expect(hello_world '').must_equal 'Hello, World!'
end
end
end
13 changes: 13 additions & 0 deletions 01-leap/leap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'awesome_print'

def leap_year?(year)
if year % 400 == 0
return true
elsif year % 4 == 0 && year % 100 > 0
return true
else
return false
end
end

ap leap_year?(1900)
9 changes: 9 additions & 0 deletions 02-robot-name/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
21 changes: 21 additions & 0 deletions 02-robot-name/robot_name.rb
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
require 'awesome_print'
require 'colorize'

class Robot
attr_reader :name

def initialize
@name = ("A".."Z").to_a.sample(2).join + rand(0..999).to_s.rjust(3, "0")
end

def reset
initialize
end
end

kate = Robot.new

puts kate.name
kate.reset
puts kate.name


3 changes: 0 additions & 3 deletions 02-robot-name/robot_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
end

it "Check that the name sticks" do
skip
robot = Robot.new
name = robot.name

Expand All @@ -27,7 +26,6 @@
end

it "Check different robots have different names" do
skip
# there is a very, very small probability of name collision here
# ensuring the name is globally unique is beyond the scope of this exercise

Expand All @@ -36,7 +34,6 @@
end

it "Check reset name" do
skip
robot = Robot.new
name = robot.name

Expand Down
33 changes: 33 additions & 0 deletions 03-hamming/hamming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# class Hamming
# attr_reader :compute

# def self.compute(string1, string2)
# raise ArgumentError if string1.length != string2.length

# hamming_distance = 0
# string1.length.times do |i|
# string1[i] == string2[i] ? next : hamming_distance += 1
# end
# return hamming_distance
# end
# end

=begin
strand1 = string1.split('')
strand2 = string2.split('')

return strand1.zip(strand2).count { |strand1, strand2| strand1 != strand2 }
zip matches each item at each index and puts them into a new coupled array:
[["A", "G"],["C, C"]...]
destructuring: strand1 and strand2 in count
=end

class Hamming
attr_reader :compute

def self.compute(string1, string2)
raise ArgumentError if string1.length != string2.length

return string1.chars.zip(string2.chars).count { |strand1, strand2| strand1 != strand2 }
end
end
24 changes: 12 additions & 12 deletions 03-hamming/hamming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,62 @@
end

it "Check complete distance in single nucleotide strands" do
skip

expect(Hamming.compute('A', 'G')).must_equal 1
end

it "Check complete distance in small strands" do
skip

expect(Hamming.compute('AG', 'CT')).must_equal 2
end

it "Check small distance in small strands" do
skip

expect(Hamming.compute('AT', 'CT')).must_equal 1
end

it "Check small distance" do
skip

expect(Hamming.compute('GGACG', 'GGTCG')).must_equal 1
end

it "Check small distance in long strands" do
skip

expect(Hamming.compute('ACCAGGG', 'ACTATGG')).must_equal 2
end

it "Check non_unique character in first strand" do
skip

expect(Hamming.compute('AGA', 'AGG')).must_equal 1
end

it "Check non unique character in second strand" do
skip

expect(Hamming.compute('AGG', 'AGA')).must_equal 1
end

it "Check large_distance" do
skip

expect(Hamming.compute('GATACA', 'GCATAA')).must_equal 4
end

it "Check large distance in off by one strand" do
skip

expect(Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT')).must_equal 9
end

it "Check Empty Strands" do
skip

expect(Hamming.compute('', '')).must_equal 0
end

it "Check disallow first strand longer" do
skip

expect ( proc { Hamming.compute('AATG', 'AAA') }).must_raise ArgumentError
end

it "Check disallow second strand longer" do
skip

expect( proc { Hamming.compute('ATA', 'AGTG') }).must_raise ArgumentError
end
end
7 changes: 7 additions & 0 deletions 04-word-count/word_count.rb
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@

def words(words)
words_array = words.split(" ")
hashify = Hash.new(0)

words_array.each { |word| hashify[word] += 1 }
return hashify
end
11 changes: 0 additions & 11 deletions 04-word-count/word_count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,72 +11,61 @@
end

it "Check counts_one_of_each" do
skip
expectedCounts = { "one" => 1, "of" => 1, "each" => 1 }

expect(words('one of each')).must_equal expectedCounts
end

it "Check counts multiple occurrences" do
skip
expectedCounts = { "one" => 1, "fish" => 4, "two" => 1, "red" => 1, "blue" => 1 }
expect(words('one fish two fish red fish blue fish')).must_equal expectedCounts
end

it "Check that it includes_punctuation" do
skip
expectedCounts = { "car" => 1, ":" => 2, "carpet" => 1, "as" => 1, "java" => 1, 'javascript!!&@$%^&' => 1 }

expect ( words('car : carpet as java : javascript!!&@$%^&') ).must_equal expectedCounts
end

it "Check includes numbers" do
skip
expectedCounts = { "testing" => 2, '1' => 1, '2' => 1 }

expect(words('testing 1 2 testing')).must_equal expectedCounts
end

it "Check respects_case" do
skip
expectedCounts = { "go" => 1, "Go" => 1, "GO" => 1 }
expect(words('go Go GO')).must_equal expectedCounts
end

it "Check counts properly international characters" do
skip
expectedCounts = { '¡Hola!' => 1, '¿Qué' => 1, 'tal?' => 1, 'Привет!' => 1 }

expect(expectedCounts).must_equal words('¡Hola! ¿Qué tal? Привет!')
end

it "Check counts_multiline" do
skip
expectedCounts = { "hello" => 1, "world" => 1 }
expect(expectedCounts).must_equal words("hello\nworld")
end

it "Check counts_tabs" do
skip
expectedCounts = { "hello" => 1, "world" => 1 }
expect(expectedCounts).must_equal words("hello\tworld")
end

it "Check counts multiple spaces as one" do
skip
expectedCounts = { "hello" => 1, "world" => 1 }
expect (expectedCounts).must_equal words('hello world')
end

it "Check does not count leading or trailing whitespace" do
skip
expectedCounts = { "Introductory" => 1, "Course" => 1 }

expect(expectedCounts).must_equal words("\t\tIntroductory\n\n\n\nCourse ")
end

it "Check handles words that are also method names" do
skip
expectedCounts = { "to_s" => 1, "gsub" => 1, "reverse" => 1, "String" => 1, "methods:" => 1 }

expect(expectedCounts).must_equal words('String methods: to_s gsub reverse')
Expand Down
33 changes: 33 additions & 0 deletions 05-alouette/alouette.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
require "pry"

class Alouette
@lyrics = [
"Et la tête!",
"Et le bec!",
"Et les yeux!",
"Et le cou!",
"Et les ailes!",
"Et les pattes!",
"Et la queue!",
"Et le dos!",
]

def self.lines_for_verse(verse_num)
return @lyrics[0..verse_num].reverse
end

def self.verse(verse_num)
current_word = lines_for_verse(verse_num).first[3..-2]
verse_lines = lines_for_verse(verse_num)
verse = "Je te plumerai #{current_word}.\nJe te plumerai #{current_word}."

verse_lines.each do |phrase|
2.times { verse += "\n" + phrase }
end

last_refrain = "\nAlouette!\nAlouette!\nA-a-a-ah"
return verse + last_refrain
end

def self.sing
transitional_refrain = "Alouette, gentille alouette,\nAlouette, je te plumerai.\n\n"
complete = transitional_refrain
i = 0
8.times do |i|
complete += verse(i) + "\n\n" + transitional_refrain
i += 1
end

return complete.strip!
end
end
Loading