Volunteering at RailsGirls Next

at Melbourne

Posted by Anton Katunin on 28 May 2016
Tags: volunteer

Spend the whole today at RailsGirls Melbourne. Met many great people and had fun. It's the first time I've done it and would recommend others to do it.

I was helping RailsGirls Next group and should say exercises were too difficult and boring as they require minimum coding and mostly mathematical logic.

Also got a funny card during ice-braker exercise

Below is my solution for the roman numerals exercise. Just like my observation earlier, I've spend most of the time thinking about logic for the solution.

# encoding: utf-8

DOZENS = {
  10 => ['I', 'V', 'X'],
  100 => ['X', 'L', 'C'],
  1_000 => ['C', 'D', 'M'],
  10_000 => ['M', "_", "+"]
}


def convert_single number, dozen
  one, five, ten = DOZENS[dozen]

  case number
  when 1..3
    one * number
  when 4
    one + five
  when 5
    five
  when 6..8
    five + (one * number)
  when 9
    one + ten
  end
end

def roman(number)
  number.to_s.chars.reverse.each_with_index.map do |char, index|
    dozen = 10 ** (index + 1)

    convert_single(char.to_i, dozen)
  end.reverse.join('')
end


require "minitest/spec"
require "minitest/autorun"

describe "roman" do
  it "converts the number 1 to the string I" do
    roman(1).must_equal 'I'
  end
  it "converts the number 1234 to the string I" do
    roman(1234).must_equal 'MCCXXXIV'
  end
  it "converts the number 4999 to the string I" do
    roman(3999).must_equal 'MMMCMXCIX'
  end
end


Read next:

Volunteering at Park Run

at Albert Part, Melbourne