odin ruby week 1

15
Odin Ruby Study Group

Upload: brian-douglas

Post on 28-May-2015

64 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: Odin ruby week 1

Odin Ruby Study Group

Page 2: Odin ruby week 1

Hello I am Brian

I will be you guide@brianllamar

ilikerobot[at]gmail

Page 3: Odin ruby week 1

Extras

Sign up for Odin G+ CommunitySign up for Ruby Newbie Group- both will assist in helpingWhile you are at it Sign up for the Ruby Community.

Page 4: Odin ruby week 1

Odin Project is open sourced

Page 5: Odin ruby week 1

In Ruby Everything is an Object

Page 6: Odin ruby week 1

Define Car Class

class Car# code goes inside

end

Page 7: Odin ruby week 1

create Car parts

class Cardef initialize # method

# part go hereend

end

Page 8: Odin ruby week 1

Create car parts

class Cardef initialize # method

@engine = Engine.new @wheels = 4.times.map { Wheel.new }end

end

Page 9: Odin ruby week 1

Let get Proceduaral (Law & Order)

Page 10: Odin ruby week 1

My approach is always different# # If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5,

6 and 9. The sum of these multiples is 23.

# # Find the sum of all the multiples of 3 or 5 below 1000.

# Pseudo

# set range 1..1000

# set the if statment to find the multiples of 3 and 5

# use if statement to add nums divisible by 3 and 5 to be added to a new_range array.

# create method that adds the new_range numbers to create a sum.

# call the Multiple class using the muli_pulls method and sum_of_multiples method

Page 11: Odin ruby week 1

class Multiples

def multi_pulls

# set range variable 1..1000

numbers = Array(1...1000) # inclusive range

multi_pulls = [] # create a new array

for i in numbers # loop that runs through every number in the array

if i % 3 == 0 || i % 5 == 0 # finds only numbers in array that are multiples of 3 and 5

multi_pulls << i # add those multiples to the new array

end

end

multi_pulls # puts final multiple array

end

def sum_of_multiples(multi_pulls) # method to find the sum of the multipes array

sum = 0 # create sum variable

multi_pulls.each {|i| sum += i } # formula to take each number in array and add to sum variable, which creates the sum of

multiples.

puts sum # returns the sum

end

end

m = Multiples.new # create a new class

m.sum_of_multiples(m.multi_pulls) # calls the sum of the multiples

Page 12: Odin ruby week 1

sample_array = (20.downto(1)).to_a # create the array 1 to 20

least_common_denominator = sample_array.inject(:lcm) # find the

least common denominator using using the lcm method between

each integer in the array

puts least_common_denominator

Page 13: Odin ruby week 1

Practice Practice Practice

Page 14: Odin ruby week 1

NewSchedule

Page 15: Odin ruby week 1

Discussion