string = "{key:[[value_1, value_2],[value_3, value4]], 5:10:00AM]}"
h = {"key" => [["value_1", "value_2"],["value_3", "value4"]], 5=>"10:00AM"}
Please note that the brackets are unbalanced on purpose.
===
# today's problem: print this page out as plain text. No images, no html tags, no javascript | |
# write a function that prints that https://www.yahoo.com/ as plain text | |
# hint: pipe that page through linx | |
# exec('lynx -dump yahoo.com') | |
File.open("yahoo_screen.txt", "w") do |f| | |
f.write %x[lynx -dump yahoo.com] | |
end |
def fizz_buzz(limit) | |
1.upto(limit).reduce("") do |string, n| | |
string << (n % 3 == 0 && n % 5 == 0 ? "FizzBuzz" : n % 3 == 0 ? "Fizz" : n % 5 == 0 ? "Buzz" : n.to_s) | |
string << "\n" | |
end | |
end |
# http://exercism.io/exercises/ruby/clock/readme | |
class Clock | |
def self.at(hours=0, minutes=0) | |
new(hours, minutes) | |
end | |
def initialize(hours=0, minutes=0) | |
array = minutes.divmod 60 |
class Player | |
def play_turn(warrior) | |
if warrior.feel.empty? | |
if warrior.health < 20 | |
if warrior.health < @health | |
if warrior.look(:backward).any?(&:enemy?) | |
warrior.shoot!(:backward) | |
else | |
if warrior.health < 10 && warrior.feel(:backward).empty? | |
warrior.walk!(:backward) |
0 info it worked if it ends with ok | |
1 verbose cli [ '/usr/local/Cellar/node/4.1.1/bin/node', | |
1 verbose cli '/usr/local/bin/npm', | |
1 verbose cli 'install', | |
1 verbose cli 'jsdom' ] | |
2 info using [email protected] | |
3 info using [email protected] | |
4 verbose install initial load of /Users/ugp/code/reactjs_koans/package.json | |
5 verbose installManyTop reading scoped package data from /Users/ugp/code/reactjs_koans/node_modules/babel/package.json | |
6 verbose installManyTop reading scoped package data from /Users/ugp/code/reactjs_koans/node_modules/babel-core/package.json |
0 info it worked if it ends with ok | |
1 verbose cli [ '/Users/ugp/.nvm/versions/node/v4.1.1/bin/node', | |
1 verbose cli '/Users/ugp/.nvm/versions/node/v4.1.1/bin/npm', | |
1 verbose cli 'install', | |
1 verbose cli 'contextify' ] | |
2 info using [email protected] | |
3 info using [email protected] | |
4 silly loadCurrentTree Starting | |
5 silly install loadCurrentTree | |
6 silly install readLocalPackageData |
# Please answer in either | |
# Ruby, | |
# Perl, | |
# PHP, | |
# Python or | |
# Java HTMLCONTROL Forms.HTML:Hidden.1 | |
# 1. Convert this string | |
# string = "{key:[[value_1, value_2],[value_3, value4]], 5:10:00AM]}" | |
# to this hash: |
class Sample | |
def initialize(hsh) | |
@hsh = hsh | |
end | |
def method_missing(method) | |
key = @hsh.has_key?(method) ? method : method.to_s | |
@hsh[key] | |
end |
result_hash = Hash.new([0, ""]) | |
File.read("path/to/file").each_line do |line| # something like that | |
line.each do |column_name, value| # a line is not an hash or nested array, but could possibly convert somehow | |
if result_hash[column_name][0] < value.length | |
result_hash[column_name][0] = value.length | |
result_hash[column_name][1] = line[factual_id] | |
end | |
end | |
end |