Skip to content

Instantly share code, notes, and snippets.

@RickGriff
RickGriff / stringy_strings.rb
Created December 11, 2017 22:02
Codewars Challenge 3 - Stringy Strings
#write me a function stringy that takes a size and returns a string of alternating '1s' and '0s'.
#the string should start with a 1.
#a string with size 6 should return :'101010'.
#with size 4 should return : '1010'.
#with size 12 should return : '101010101010'.
#The size will always be positive and will only use whole numbers.
#My Solution:
@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 / jenny_message.rb
Created December 11, 2017 21:57
Codewars Challenge 1 - Jenny's Secret Message
#Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would
#like to greet him slightly different. She added a special case to her function, but she made a mistake.
#Can you help her?
#Initial Code with Error:
def greet(name)
return "Hello, #{name}!"
return "Hello, my love!" if name == "Johnny"
end
@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