- go to exercism.io and login with github account
- get your api key (navbar > username > api key)
- install exercism
brew install exercism
in OSX - and set api key to exercism cli http://exercism.io/cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Clock | |
def self.at(hours=0, minutes=0) | |
new(hours, minutes) | |
end | |
def initialize(hours=0, minutes=0) | |
array = minutes.divmod 60 | |
@minutes = array[1] | |
@hours = array[0] + hours |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Today's kata: | |
# Given a 3 or 4 digit number with distinct digits, return a sorted array of all the unique numbers that can be formed with those digits. | |
# ie, given 123, return [123, 132, 213, 231, 312, 321] | |
def same_digit_numbers(initial_num) | |
initial_num.to_s.split('').permutation.map {|e| e.join.to_i }.uniq.sort | |
end | |
def same_digit_numbers(initial_num) | |
num_string = initial_num.to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# today's code kata: Write a function called word_count, that takes a sentence as a string as input, and returns the frequency of each word in that sentence, as a hash whose key is the word, and whose count is the number of times that word appears in that sentence. | |
# 1) ignore case, 2) ignore any non word characters | |
# Here is the paragraph: | |
# The quick brown fox jumped over the moon. This mammal did not jump over the sun; it jumped over the moon. And it was quick about it. | |
# let's use the whole paragraph | |
def word_count(paragraph) | |
paragraph.split(/\W+/).map(&:downcase).each_with_object(Hash.new(0)) {|w, hsh| hsh[w] += 1 } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# She has asked you to create a method print_puzzle that prints the row of dashes for a required, single argument, word. The number of dashes or spaces should equal the amount of characters in the word. print_puzzle can also optionally take a list of characters as a second argument that represents the list of guessed letters. | |
# Given print_puzzle is called with the word "perimeter", your method should output: _ _ _ _ _ _ _ _ _ | |
# Given print_puzzle is called with the word "triangle" and the list of characters guessed: t,s,g, your method should output: t _ _ _ _ g _ _ | |
def print_puzzle(word, guessed_letters = []) | |
word.chars.map {|char| guessed_letters.include?(char) ? " #{char}" : " _"}.join | |
end | |
gem 'minitest' | |
require 'minitest/autorun' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'minitest', '>= 5.0.0' | |
require 'minitest/autorun' | |
def reverse(string) | |
result = "" | |
string.length.times do |i| | |
result = string[i] + result | |
end | |
result | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For today, here's the problem for today | |
# Do whatever you need to do to Ruby, such that I can say: 9 - 8, and the answer will be 17 | |
# And if I say 9 + 8, the answer will be 1 | |
# so - i load whatever code you want to give me via a console, and I should be able to do the above | |
# turn plus into minus, minus into plus | |
# a short sentence explaining what you did and why it works would be nice | |
class Fixnum | |
alias_method :temp, :+ | |
alias_method :+, :- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add a logger to this class, such that there is only one logger, that writes to a file called ./logfile.txt | |
class Charlie | |
class Logger | |
def self.log(number) | |
File.open("./logfile.txt", "a") do |f| | |
f.puts "#{number}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
# Question 1. A mixin is a module whose methods you want to use in more than one class. One popular interview question is: How do you use module methods as class methods, and how to you use them as instance methods? In other words, given this module ... | |
module Mixin | |
def method1 | |
'method1' | |
end | |
end |
- install command-line tool matching OS X version
- homebrew / npm
sudo chown -R $(whoami):admin /usr/local
- eventmachine
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" gem install eventmachine