-
This ruby script converts a number to it's text form. For example, 542 is five hundred and forty two.
-
Use the download button above to grab a copy.
-
This requires a ruby version > 1.9
$ ruby -v
#!/usr/bin/env ruby | |
for i in 1..100 | |
if(i % 5 == 0 and i % 3 == 0) | |
puts "FizzBuzz" | |
elsif(i % 3 == 0) | |
puts "Fizz" | |
elsif(i % 5 == 0) | |
puts "Buzz" | |
else |
Solve the XKCD Bridge puzzle
$ ./bridge-test.rb
Loaded suite ./bridge-test
Started
C and D crossed over in 2 minutes.
D crossed back in 1 minutes.
#!/usr/bin/env ruby | |
str = " this is some text with spaces in it " | |
puts str.split.join | |
#Output: thisissometextwithspacesinit |
def fizzbuzz(n) | |
str = "" | |
str << (n % 3 == 0 ? "fizz" : "") | |
str << (n % 5 == 0 ? "buzz" : "") | |
end | |
list = ["fizz", "fizz", "buzz"] | |
arr = (1..100).map { |n| [n, fizzbuzz(n)] }.reject { |h| h.last.empty? } | |
res = arr.each_slice(list.length).to_a.find_all do |slice| |
#ZSH | |
echo "installing zsh" | |
sudo apt-get install -y zsh | |
#Git | |
echo "installing git" | |
sudo apt-get install -y git-core | |
#Oh My Zsh | |
echo "installing oh-my-zsh" |
require 'rubygems' | |
require 'mechanize' | |
def fetch_podcast_links_from_index_page(index_link) | |
agent = Mechanize.new | |
agent.get(index_link) | |
story_links = agent.page.links.find_all { |l| l.text.include? ':' } | |
story_links.map do |link| | |
link.click |
class Chest | |
attr_reader :type, :index, :keys | |
def initialize(array, index) | |
@type = array.shift.to_i | |
@keys = array.shift(array.shift.to_i).map(&:to_i) | |
@index = index | |
end | |
def unlock | |
@keys |