Skip to content
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
9 changes: 9 additions & 0 deletions combinations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def combinations(arr1, arr2)
return_arr = []
arr1.each_with_index do |word1, index1|
arr2.each_with_index do |word2, index2|
return_arr << word1 + word2
end
end
return_arr
end
42 changes: 42 additions & 0 deletions counting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def counting(players, count)
def rotate_player(up, player, players)
if up
if player < players
player += 1
else
player = 1
end
else
if player > 1
player -= 1
else
player = players
end
end
end

up = true
player = 1

(1..count).each do |x|
#skip a player if count is divisible by 11
# if x % 11 == 0
# player = rotate_player(up, player, players)
# end
#print number and corresponding number

puts "The number #{x} was spoken by player #{player}"

#change direction if divisible by seven
if x % 7 == 0
up = !up
end

player = rotate_player(up, player, players)

if x % 11 == 0
player = rotate_player(up, player, players)
end
end

end
7 changes: 7 additions & 0 deletions factorial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def factorial(num)
answer = 1
(1..num).each do |x|
answer *= x
end
answer
end
13 changes: 13 additions & 0 deletions overlap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def overlap(n, m)
#list of sides:
firstleft = n[0][0]
firstbottom = n[0][1]
firstright = n[1][0]
firsttop = n[1][1]
secondleft = m[0][0]
secondbottom = m[0][1]
secondright = m[1][0]
secondtop = m[1][1]

firstleft < secondright && firsttop > secondbottom && firstright > secondleft && firstbottom < secondtop
end
7 changes: 7 additions & 0 deletions power.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def power(base,exponent)
answer = 1
exponent.times do
answer *= base
end
answer
end
5 changes: 5 additions & 0 deletions primes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def is_prime?(num)
return false if num <= 1
Math.sqrt(num).to_i.downto(2).each {|i| return false if num % i == 0}
true
end
11 changes: 11 additions & 0 deletions uniques.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def uniques(x)
final = []
#loop over entire array
x.each_with_index do |v, i|
unless final.include?(v)
final.push(v)
end
end
#return array
final
end