DevHeads.net

Postings by Frank J. Cameron

Re: Ruby Quiz - Challenge #9 - Tally Up / Calculate the Standings Table for the English Premier League 2018/19 Season - And the Winner is... Liverpool? Manchester City?

Gerald Bauer wrote:
$ ruby -v lib/009.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Run options: --seed 17997
# Running:
..
Finished in 0.009669s, 206.8368 runs/s, 206.8368 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

$ cat lib/009.rb
require_relative '../009/test.rb'
class RubyQuizTest
#
# [ Team 1, Raw Score (Score 1 - Score 2), Team 2 ]
#
# Team Name:
# [ 0: Played | 1: Won | 2: Drawn | 3: Lost |
# | 4: Goals for | 5: Goals against

Re: Ruby Quiz - Challenge #6 - Build the Table of Contents (ToC) for Documents in Markdown

Gerald Bauer wrote:

$ ruby ./lib/006a.rb
Run options: --seed 21628
# Running:
.
Finished in 0.003442s, 290.5411 runs/s, 290.5411 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

$ cat ./lib/006a.rb
require_relative '../006/test.rb'

class RubyQuizTest
def toc(txt)
txt
.lines
.lazy
.select{|l| l.match(/^(#+)\s+(.*)\s*$/)}
.map{|l| [$~[1].length, $~[2]]}
.slice_when{|a, b| a[0] != b[0]}
.to_a
.yield_self do |z|
# <a href="https://en.wikipedia.org/wiki/Overfi" title="https://en.wikipedia.org/wiki/Overfi">https://en.wikipedia.org/wiki/Overfi</a>

Re: Ruby Quiz - Challenge #4 - Turn Humanitarian eXchange Language (HXL) Tabular Records into Named Tuples

Gerald Bauer wrote:
$ ruby ./lib/004.rb
Run options: --seed 28092
# Running:
.F
Finished in 0.005780s, 346.0336 runs/s, 346.0336 assertions/s.
1) Failure:
RubyQuizTest#test_level2 [/home/fjc/ruby-quiz/004/test.rb:71]:
--- expected
+++ actual
@@ -1 +1 @@
-[{"sector+en"=>"WASH", "subsector"=>"Subsector 1", "org"=>"Org 1",
"country"=>"Country 1", "sex+targeted"=>["100", "100"], "adm1"=>"Region
1"}, {"sector+en"=>"Health", "subsector"=>"Subsector 2", "org"=>"Org 2",
"country"=>"Country 2", "sex+targ

Re: Ruby Quiz - Challenge #3 - Read the English Premier League (EPL) Standings Table from a Web Page

Gerald Bauer wrote:
$ ruby lib/003.rb
Run options: --seed 2712
# Running:
[["1", "Man City", "10", "8", "2", "0", "27", "3", "24", "26"],
["2", "Liverpool", "10", "8", "2", "0", "20", "4", "16", "26"],
["3", "Chelsea", "10", "7", "3", "0", "24", "7", "17", "24"],
["4", "Arsenal", "10", "7", "1", "2", "24", "13", "11", "22"],
["5", "Tottenham", "10", "7", "0", "3", "16", "8", "8", "21"],
["6", "Bournemouth", "10", "6", "2", "2", "19", "12", "7", "20"], ["7",
"Watford", "10", "6", "1", "3", "16", "12", "

Re: Ruby Quiz - Challenge #2 - Calculate the Bitcoin Genesis Block Hash (SHA-256)

$ ruby lib/002.rb
Run options: --seed 62016
# Running:
.
Finished in 0.002718s, 367.9076 runs/s, 367.9076 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

$ cat lib/002.rb
require_relative '../002/test.rb'
require 'digest'
class RubyQuizTest
def calculate(v, p, m, t, b, n)
Digest::SHA256.digest(
Digest::SHA256.digest(
[v].pack('V') \
+ [p].pack('H*').reverse \
+ [m].pack('H*').reverse \
+ [t].pack('V') \
+ [b].pack('H*').reverse \

Re: Ruby Quiz is Back - Challenge #1 - Read Comma-Separated Values (CSV) from the "Real World"

$ ruby lib/1.rb
Run options: --seed 19056
# Running:
.
Finished in 0.002289s, 436.9176 runs/s, 436.9176 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

$ cat lib/1.rb
require_relative '../test/1.rb'
class RubyQuizTest
def parse(text)
text.lines.map do |line|
next if line.match(/^\s*$|#/)
line.strip.split(/\s*,\s*/, -1)
end.compact.map do |cells|
cells.map do |cell|
cell.match(/"(.*)"/) ?