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

Ruby Judo #127

Open
wants to merge 4 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
11 changes: 11 additions & 0 deletions combinations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def combinations(arrayOne, arrayTwo)
result=[]
arrayOne.each do |string|
arrayTwo.each do |string2|
result.push(string + string2)
end
end
return result
end

puts combinations(["hi", "bye", "hey", "jeff"], ["kayla", "john", "joe", "josh"])
10 changes: 10 additions & 0 deletions factorial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def factorial(number)
result = 1
(1..number).each do |num|
result = result * num
end
return result
end

puts factorial(5)

35 changes: 35 additions & 0 deletions overlap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def overlap(recArray1, recArray2)

width1 = (recArray1[0][0]...recArray1[1][0])
height1 = (recArray1[0][1]...recArray1[1][1])
width2 = (recArray2[0][0]...recArray2[1][0])
height2 = (recArray2[0][1]...recArray2[1][1])

heightOverlap = false
widthOverlap = false
overlap = false

width1.each do |range|
if width2.include? range
widthOverlap = true
end
end

height1.each do |range|
if height2.include? range
heightOverlap = true
end
end

if heightOverlap == true and widthOverlap == true
overlap = true
else
overlap = false
end
return overlap
end

puts overlap([[0,0], [3,3]], [[1,1], [4,5]])
puts overlap([[0,0], [1,4]], [[1,1], [3,2]])


9 changes: 9 additions & 0 deletions power.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def power(base, exponent)
result = 1
exponent.times do
result = result * base
end
return result
end

puts power(8,3)
16 changes: 16 additions & 0 deletions primes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_prime? (number)
result = true
quotient = 2
while (quotient < number) and result == true
if number%quotient == 0
result = false
else
quotient += 1
end
end
return result
end

puts is_prime?(7)
puts is_prime?(3)
puts is_prime?(14)
12 changes: 12 additions & 0 deletions uniques.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def uniques(originalArray)
result = []
originalArray.each do |item|
unless result.include? item
result.push(item)
end
end
return result
end


puts uniques([1,5,5,2])