Skip to content

Commit

Permalink
week 3 exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejc committed Sep 7, 2012
1 parent 60d829f commit 3c5de30
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Created by Satish
Thank God!
121 changes: 121 additions & 0 deletions text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Among other public buildings in a certain town, which for many
reasons it will be prudent to refrain from mentioning, and to
which I will assign no fictitious name, there is one anciently
common to most towns, great or small: to wit, a workhouse; and
in this workhouse was born; on a day and date which I need not
trouble myself to repeat, inasmuch as it can be of no possible
consequence to the reader, in this stage of the business at all
events; the item of mortality whose name is prefixed to the head
of this chapter.

For a long time after it was ushered into this world of sorrow
and trouble, by the parish surgeon, it remained a matter of
considerable doubt whether the child would survive to bear any
name at all; in which case it is somewhat more than probable that
these memoirs would never have appeared; or, if they had, that
being comprised within a couple of pages, they would have
possessed the inestimable merit of being the most concise and
faithful specimen of biography, extant in the literature of any
age or country.

Although I am not disposed to maintain that the being born in a
workhouse, is in itself the most fortunate and enviable
circumstance that can possibly befall a human being, I do mean to
say that in this particular instance, it was the best thing for
Oliver Twist that could by possibility have occurred. The fact
is, that there was considerable difficulty in inducing Oliver to
take upon himself the office of respiration,--a troublesome
practice, but one which custom has rendered necessary to our easy
existence; and for some time he lay gasping on a little flock
mattress, rather unequally poised between this world and the
next: the balance being decidedly in favour of the latter. Now,
if, during this brief period, Oliver had been surrounded by
careful grandmothers, anxious aunts, experienced nurses, and
doctors of profound wisdom, he would most inevitably and
indubitably have been killed in no time. There being nobody by,
however, but a pauper old woman, who was rendered rather misty by
an unwonted allowance of beer; and a parish surgeon who did such
matters by contract; Oliver and Nature fought out the point
between them. The result was, that, after a few struggles,
Oliver breathed, sneezed, and proceeded to advertise to the
inmates of the workhouse the fact of a new burden having been
imposed upon the parish, by setting up as loud a cry as could
reasonably have been expected from a male infant who had not been
possessed of that very useful appendage, a voice, for a much
longer space of time than three minutes and a quarter.

As Oliver gave this first proof of the free and proper action of
his lungs, the patchwork coverlet which was carelessly flung over
the iron bedstead, rustled; the pale face of a young woman was
raised feebly from the pillow; and a faint voice imperfectly
articulated the words, 'Let me see the child, and die.'

The surgeon had been sitting with his face turned towards the
fire: giving the palms of his hands a warm and a rub
alternately. As the young woman spoke, he rose, and advancing to
the bed's head, said, with more kindness than might have been
expected of him:

'Oh, you must not talk about dying yet.'

'Lor bless her dear heart, no!' interposed the nurse, hastily
depositing in her pocket a green glass bottle, the contents of
which she had been tasting in a corner with evident satisfaction.

'Lor bless her dear heart, when she has lived as long as I have,
sir, and had thirteen children of her own, and all on 'em dead
except two, and them in the wurkus with me, she'll know better
than to take on in that way, bless her dear heart! Think what it
is to be a mother, there's a dear young lamb do.'

Apparently this consolatory perspective of a mother's prospects
failed in producing its due effect. The patient shook her head,
and stretched out her hand towards the child.

The surgeon deposited it in her arms. She imprinted her cold
white lips passionately on its forehead; passed her hands over
her face; gazed wildly round; shuddered; fell back--and died.
They chafed her breast, hands, and temples; but the blood had
stopped forever. They talked of hope and comfort. They had been
strangers too long.

'It's all over, Mrs. Thingummy!' said the surgeon at last.

'Ah, poor dear, so it is!' said the nurse, picking up the cork of
the green bottle, which had fallen out on the pillow, as she
stooped to take up the child. 'Poor dear!'

'You needn't mind sending up to me, if the child cries, nurse,'
said the surgeon, putting on his gloves with great deliberation.
'It's very likely it WILL be troublesome. Give it a little gruel
if it is.' He put on his hat, and, pausing by the bed-side on
his way to the door, added, 'She was a good-looking girl, too;
where did she come from?'

'She was brought here last night,' replied the old woman, 'by the
overseer's order. She was found lying in the street. She had
walked some distance, for her shoes were worn to pieces; but
where she came from, or where she was going to, nobody knows.'

The surgeon leaned over the body, and raised the left hand. 'The
old story,' he said, shaking his head: 'no wedding-ring, I see.
Ah! Good-night!'

The medical gentleman walked away to dinner; and the nurse,
having once more applied herself to the green bottle, sat down on
a low chair before the fire, and proceeded to dress the infant.

What an excellent example of the power of dress, young Oliver
Twist was! Wrapped in the blanket which had hitherto formed his
only covering, he might have been the child of a nobleman or a
beggar; it would have been hard for the haughtiest stranger to
have assigned him his proper station in society. But now that he
was enveloped in the old calico robes which had grown yellow in
the same service, he was badged and ticketed, and fell into his
place at once--a parish child--the orphan of a workhouse--the
humble, half-starved drudge--to be cuffed and buffeted through
the world--despised by all, and pitied by none.

Oliver cried lustily. If he could have known that he was an
orphan, left to the tender mercies of church-wardens and
overseers, perhaps he would have cried the louder.
3 changes: 3 additions & 0 deletions text2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I love my dog. Go. How are you?

I love you.
2 changes: 2 additions & 0 deletions tmp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
f = ARGV[0]
puts f
33 changes: 33 additions & 0 deletions w2ex3retry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def leap_year(year)
if year%4==0
if year%100==0
if year%400==0
leap_year = true
else
leap_year = false
end
else
leap_year = true
end
else
leap_year = false
end
if leap_year == true
yield(366*24*60, leap_year)
else
yield(365*24*60, leap_year)
end
end
puts"Enter a year and I will tell you if it's a leap year"
print"? "
STDOUT.flush
year = gets.to_i
leap_year(year) {|minutes, leap_year|
if leap_year == true
puts "#{year} is a leap year."
puts "There are #{minutes} minutes in a leap year."
else
puts "#{year} is not a leap year"
puts "There are #{minutes} minutes in a non leap year."
end
}
7 changes: 7 additions & 0 deletions w3ex10.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
collection = [1,2,3,4,5]
sum = 0
collection.each do |x|
sum += x
end

puts sum
19 changes: 19 additions & 0 deletions w3ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
print "Enter the file to be evaluated: > "
file = gets.chomp

replacement_file = ""

File.open(file, 'r') do |f|
while line = f.gets
line["word"] = "inserted word" if line.include?("word")
replacement_file << line
end
end

File.open(file, 'w') do |f|
f.puts replacement_file
end




19 changes: 19 additions & 0 deletions w3ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Displays the current working directory
original_directory = Dir.getwd
puts original_directory

#Creates new directory called tmp
Dir.mkdir('tmp')

#Changes the directory to tmp
Dir.chdir('tmp')

#Displays the current working directory
puts Dir.getwd

#goes back to original wprking directory
Dir.chdir(original_directory)
puts Dir.getwd

#delete the tmp directory
Dir.delete('tmp')
5 changes: 5 additions & 0 deletions w3ex5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

s = 'key=value'
s1, s2 = s.split('=')
puts s1
puts s2
16 changes: 16 additions & 0 deletions w3ex6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

you_say = ""

until you_say == "BYE"

print "You say to Grandma > "
you_say = gets.chomp

if you_say != you_say.upcase
puts "HUH?! SPEAK UP, SONNY"
elsif you_say != "BYE"
puts "NO, NOT SINCE #{rand(1938...1950)}"
end
end

puts "Grandma walks away."
33 changes: 33 additions & 0 deletions w3ex7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
line_count = 0

File.open('text.txt') do |f|
while line = f.gets
line_count += 1
end
end


new_file = File.read('text.txt')
puts new_file.class

character_count = new_file.scan(/./).size
character_count_wo_spaces = (character_count) - (new_file.count " ")

word_count = new_file.scan(/\w+/).size
sentence_count = new_file.scan(/((?<=[a-z0-9)][.?!])|(?<=[a-z0-9][.?!]"))\s+(?="?[A-Z])/).size
paragraph_count = new_file.scan(/\n\n/).size

average_num_words_per_sentence = word_count.to_f / sentence_count
average_num_sentences_per_paragraph = sentence_count.to_f / paragraph_count

puts "There are #{character_count} characters in the file"
puts "There are #{character_count_wo_spaces} characters not including spaces in the file"
puts "There are #{line_count} lines in the file"
puts "There are #{word_count} words in the file"
puts "There are #{sentence_count} sentences in the file"
puts "There are #{paragraph_count} paragraphs in the file"
puts "There are an average of #{average_num_words_per_sentence} words per sentence in the file"
puts "There are an average of #{average_num_sentences_per_paragraph} sentences per paragraph in the file"



9 changes: 9 additions & 0 deletions w3ex8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(1..100).each do |count|
output = ""
output = "Fizz" if count % 3 == 0
output += "Buzz" if count % 5 == 0
output = count if output == ""

puts output

end
15 changes: 15 additions & 0 deletions w3ex9.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def reverse_string_word_order(string)
words = []
words << string.split(" ")
reverse_string = ""
words[0].reverse_each { |x| reverse_string<< x + " "}
yield(reverse_string)

end

print "Enter a string: > "
STDOUT.flush
string = gets.chomp

reverse_string_word_order(string){|reverse_string| puts reverse_string}

14 changes: 14 additions & 0 deletions word.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test test test test test
test test test test test
test test test test test
test test test test test
test test test test test
test test inserted inserted word test test
test test test test test
test test test test test
test test test test test
test test test test test

test test test test test2

hello

0 comments on commit 3c5de30

Please sign in to comment.