Skip to content

Instantly share code, notes, and snippets.

@RickGriff
RickGriff / tube_strike.rb
Last active January 7, 2018 22:33
Codewars Challenge: Tube Strike Options Calculator
# Tube strike options calculator
# The sweaty bus ride
# There is a tube strike today so instead of getting the London Underground home you have decided to take the bus. It's a hot day and you have been sitting on the bus for over an hour, but the bus is hardly moving. Your arm is sticking to the window and sweat drips off your nose as you try to read your neighbour's book when you say to yourself, "This is ridiculous. I could have walked faster than this!" Suddenly you have an idea for an app that helps people decide whether to walk or take the bus home when the London Underground is on strike.
# You rush home (relatively speaking) and begin to define the function that will underpin your app.
# Function specification
# You must create a function which takes three parameters; walking distance home, distance the bus must travel, and the combined distance of walking from the office to the bus stop and from the bus stop to your house. All distances are in kilometres.
# So for example, if your home is 5km away b
@RickGriff
RickGriff / sum_diagonal.rb
Created December 11, 2017 22:07
Codewars Bonus Challenge 4 - Find The Sum of Diagonal 1's
#Given a "square" array of subarrays, find the sum of values from the first value of the first array,
#the second value of the second array, the third value of the third array, and so on...
#Example 1:
#exampleArray = [[1, 0, 0, 0],
# [0, 1, 0, 0],
# [0, 0, 1, 0],
# [0, 0, 0, 1]]
@RickGriff
RickGriff / count_by_x.rb
Created December 11, 2017 22:00
Codewars Challenge 2 - Count by X
#Create a function with two arguments that will return a list of length (n) with multiples of (x).
#Assume both the given number and the number of times to count will be positive numbers greater than 0.
#Return the results as an array (or list in Python, Haskell or Elixir).
#Examples:
#count_by(1,10) should return [1,2,3,4,5,6,7,8,9,10]
#count_by(2,5) should return [2,4,6,8,10]
#My Solution:
def count_by(x, n)
@RickGriff
RickGriff / my_array_solutions.rb
Created December 8, 2017 13:52
Solutions to my_array.rb Stretch Challenge
class Array
def my_each(&block)
for i in self
yield i
end
end
def my_map(&block)
arr = []
for i in self