Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ab149d5
assignment01 complete
christopeak Jan 9, 2015
5cbaaf3
resolved conflicts in assignment1
christopeak Jan 19, 2015
2852082
assignment 2 tasks 1-3 complete
christopeak Jan 20, 2015
95270f0
started assignemtn 2 problem 4
christopeak Jan 20, 2015
cc89d86
another try at assignment 2 problem 4
christopeak Jan 21, 2015
e710e7b
some progress on assignment 2 problem 4
christopeak Jan 22, 2015
952bfef
a bit more incrementalprogress on assignment 2 problem 4
christopeak Jan 22, 2015
b00f301
assignment 2 for submission
christopeak Jan 23, 2015
91c73bd
more assignment 2 progress
christopeak Jan 25, 2015
f1ec2f9
completed assignment 2
christopeak Jan 25, 2015
518c459
merged with origin in order to begin assignment 3
christopeak Jan 25, 2015
821c65b
completed assignment 3 problems 1 and 2
christopeak Jan 25, 2015
2aa78e6
worked on assignement 3 problem 3
christopeak Jan 28, 2015
823f1b5
progress on assignment 3 problem 3
christopeak Jan 28, 2015
10670f2
more assignment 3 progress
christopeak Jan 29, 2015
a1f2353
a coupld of minor edits to assignemnt 3
christopeak Jan 29, 2015
34e9923
Chris Peak's assignment 3 submission
christopeak Jan 30, 2015
5b3a94e
resolved conflicts in assignment02.rb
christopeak Feb 3, 2015
7e29354
assignemnt 4 problems 1 and 2 complete
christopeak Feb 4, 2015
1e2f5d9
started assignment 4 problem 3
christopeak Feb 4, 2015
a50fa97
some progress on assignemnt 4 problem 3
christopeak Feb 5, 2015
fab8a13
Assignment 4 submission -- Chris Peak
christopeak Feb 5, 2015
e74ceda
minor tweak to LinkedList class to improve the list order
christopeak Feb 6, 2015
0421073
Merge branch 'master' of https://github.com/planetcohen/uw-ruby-101
christopeak Feb 8, 2015
3b95cae
begin assignment 5
christopeak Feb 9, 2015
03e5395
completed assignment 5
christopeak Feb 10, 2015
3fa673b
Merge branch 'master' of https://github.com/planetcohen/uw-ruby-101
christopeak Feb 14, 2015
bd3d3da
assignment 6 complete but wants refactoring
christopeak Feb 16, 2015
1d9bb8b
assignment 6 problem 2 string formatting moderately acceptable
christopeak Feb 16, 2015
adb7217
heredoc rendering is more acceptable now.
christopeak Feb 16, 2015
375a542
Merge branch 'master' of https://github.com/planetcohen/uw-ruby-101
christopeak Feb 21, 2015
95e2c4d
assignment 7
christopeak Feb 23, 2015
c36d0d7
Merge branch 'master' of https://github.com/planetcohen/uw-ruby-101
christopeak Feb 28, 2015
3a9113d
asgmt 8 problem 1 version 1
christopeak Mar 2, 2015
d3ffaa4
asgmt 8 problem 1 version 2
christopeak Mar 2, 2015
2c32868
asgmt 8 problem 1 complete
christopeak Mar 2, 2015
53d3fd6
assignment 8 problem 2 initial attempt
christopeak Mar 2, 2015
71c298a
assignment 8 complete (except for bonus excercises)
christopeak Mar 2, 2015
5a070ba
added further tests to RomanNumeralTest
christopeak Mar 2, 2015
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
86 changes: 86 additions & 0 deletions assignments/asgmt6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
require 'minitest/autorun'

class PriorityQueue

class SubQueue
attr :rank, :items
def initialize(rank)
@rank = rank
@items = []
end
def enqueue(item)
@items<<item
end
def dequeue
@items.shift
end
def empty?
@items.empty?
end
def peek
@items[0]
end
def length
@items.length
end
end #SubQueue

def initialize
@high_sq = SubQueue.new(:high)
@medium_sq = SubQueue.new(:medium)
@low_sq = SubQueue.new(:low)
@sq_names = {high: @high_sq, medium: @medium_sq, low: @low_sq}
end
def enqueue(item, priority=:medium)
subqueue = @sq_names.select {|i| i == priority}.values[0]
subqueue.enqueue(item)
end
def dequeue
if @high_sq.length > 0
@high_sq.dequeue
elsif @medium_sq.length > 0
@medium_sq.dequeue
else
@low_sq.dequeue
end
end
def empty?
ary = @high_sq.items + @medium_sq.items + @low_sq.items
ary.empty?
end
def peek
if @high_sq.length > 0
@high_sq.peek
elsif @medium_sq.length > 0
@medium_sq.peek
else
@low_sq.peek
end
end
def length
ary = @high_sq.items + @medium_sq.items + @low_sq.items
ary.length
end
end #PriorityQueue


class TestPriorityQueue < MiniTest::Test
def test_one
pq = PriorityQueue.new
assert pq.empty?
pq.enqueue "first"
refute pq.empty?

pq.enqueue "top", :high
pq.enqueue "last", :low
pq.enqueue "second"
pq.enqueue "another top", :high
assert_equal 5, pq.length

assert_equal "top", pq.dequeue
assert_equal "another top", pq.dequeue
assert_equal "first", pq.dequeue
assert_equal "second", pq.dequeue
assert_equal "last", pq.dequeue
end
end #class
72 changes: 72 additions & 0 deletions assignments/asgmt8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@


module Assignment08
class RomanNumeral
attr :value, :arabic_digits
def initialize(i)
@value = i
@arabic_digits = []
[0,1,2].each {|n| @arabic_digits[n] = @value.to_s[(n+1) *-1].to_i}
end

def to_s
roman_chars = []
roman_chars << %w{I IV V IX}
roman_chars << %w{X XL L XC}
roman_chars << %w{C CD D CM}
r_numeral = ""
r_digit = ""
@arabic_digits.each_with_index do |arabic_digit, i|
if arabic_digit <= 3 then
r_digit = roman_chars[i][0] * arabic_digit
elsif arabic_digit == 4 then
r_digit = roman_chars[i][1]
elsif arabic_digit <= 8 then
r_digit = roman_chars[i][2] + roman_chars[i][0] * (arabic_digit - 5)
else r_digit = roman_chars[i][3]
end
r_numeral.insert(0, r_digit)
end
r_numeral
end

def to_i
@value
end

# bonus: create from Roman Numeral
def self.from_string(rn)
# returns a new instance
rn == 'III' ? @value = 3 : @value = nil #MOREMORE method in process
end
end

# bonus:
#RomanNumeral.from_string('III').to_i # => 3
#RomanNumeral.from_string('IX').to_i # => 9
#RomanNumeral.from_string('IX').to_i # => 9

#require Assignment08

require 'minitest/autorun'

class RomanNumeralTest < MiniTest::Test
def test_one
assert_equal 'I', RomanNumeral.new(1).to_s
assert_equal 'II', RomanNumeral.new(2).to_s
assert_equal 'III', RomanNumeral.new(3).to_s
assert_equal 'IV', RomanNumeral.new(4).to_s
assert_equal 'V', RomanNumeral.new(5).to_s
assert_equal 'VI', RomanNumeral.new(6).to_s
assert_equal 'VII', RomanNumeral.new(7).to_s
assert_equal 'IX', RomanNumeral.new(9).to_s
assert_equal 'X', RomanNumeral.new(10).to_s
assert_equal 'XIX', RomanNumeral.new(19).to_s
assert_equal 'XXXII', RomanNumeral.new(32).to_s
assert_equal 'LI', RomanNumeral.new(51).to_s
assert_equal 'C', RomanNumeral.new(100).to_s
assert_equal 'CI', RomanNumeral.new(101).to_s
end
end
end

39 changes: 22 additions & 17 deletions assignments/assignment01.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ def number_to_string(n, lang)
# it accepts a string
# and returns the same string with each word capitalized.
def titleize(s)
words = s.split
caps = []
words.each do |word|
caps << word.capitalize
end
caps.join " "
my_words = s.split(" ")
cap_sentence = ""
my_words.each {|w| cap_sentence << w.capitalize << " "}
cap_sentence.chop

end

# Your method should generate the following results:
titleize "hEllo WORLD" #=> "Hello World"
puts titleize "hEllo WORLD" #=> "Hello World"

titleize "gooDbye CRUel wORLD" #=> "Goodbye Cruel World"
puts titleize "gooDbye CRUel wORLD" #=> "Goodbye Cruel World"


# ========================================================================================
Expand All @@ -58,14 +57,13 @@ def titleize(s)
# Write your own implementation of `reverse` called `my_reverse`
# You may *not* use the built-in `reverse` method
def my_reverse(s)
output = ""
letters = s.split ""
n = letters.length
while n > 0
n -= 1
output << letters[n]
s_array = s.split("")
s_array_reverse = []
s_array.each { |c| s_array_reverse.insert(0, c)
end
output
s_reverse = s_array_reverse.join


end

# Your method should generate the following results:
Expand All @@ -80,8 +78,15 @@ def my_reverse(s)
# Write a method `palindrome?`
# that determines whether a string is a palindrome
def palindrome?(s)
stripped = s.delete(" ").delete(",").downcase
stripped == stripped.reverse
s1 = s.sub(' ', '').downcase
s2 = s1.reverse

if s2 == s1
true
else
false
end

end

# Your method should generate the following results:
Expand Down
Loading