-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day1HW.rb
67 lines (67 loc) · 1.88 KB
/
Day1HW.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#bullet 1
puts "Question 1: "
def hypotenuse(side_a, side_b)
side_c=(((side_a**2.0)+(side_b**2.0))**(1.0/2.0))
puts "If Side A and B are equal to #{side_a} and #{side_b} inches respectively, then Side C is equal to #{side_c}."
end
puts "We shall be geting the hypotemoose for two sides. Please input side A: "
side_a = gets.chomp!.to_i
puts "Please input side B: "
side_b = gets.chomp!.to_i
hypotenuse(side_a,side_b)
puts ""
puts ""
puts "Question 2"
puts "A couple methods that strings have that symbols don't are"
puts "strip! = removes whitespace from str. Returns 'nil' if not altered."
puts "rjust = if a string is bigger than the integer, it doesn't change. If integer is bigger, then it pads any extra space."
puts "bytes = returns an array of bytes"
puts ""
puts "A couple that symbols have that strings don't are"
puts "pretty_print_cycle"
puts "to_proc"
puts "id2name"
puts ""
puts "Question 3"
puts "Fixnum are immutable objects. They cannot be changed after being created. It is Ruby's job to create the Fixnum object, not ours."
puts ""
puts "Question 4"
def random(n)
puts "apple".rjust(n, "sn")
bill = [ :a, 7, "b", 8, :c, 7]
puts bill.grep(7)
hashy = {a: 1, b: 2, c: 3}
hashy[:a] = n
puts #{hashy}
end
random(7)
puts ""
puts "Question 5"
class Musher
def initialize separator
@separator = separator
end
def mush words
words.join(" #{@separator} ").to_s
end
end
trial = Musher.new("+").mush(["array", "of", "strings"])
puts trial
puts ""
puts "Question 6"
class Averager
def initialize(first_number, second_number)
avg=((first_number+second_number)/2.0)
puts "Your average is #{avg}!"
end
end
puts "What two numbers would you like averaged?"
puts "First Number: "
first_number = gets.chomp!.to_i
puts "Second Number: "
second_number = gets.chomp!.to_i
Averager.new(first_number, second_number)
puts ""
puts "Question 7"
a = IO.readlines("Day1HW.rb")
puts a[rand(0..66)]