Skip to content

Instantly share code, notes, and snippets.

@fractalatcarf
Created April 3, 2017 15:37
Show Gist options
  • Save fractalatcarf/1f773e613c32210672eb8ab36b535a78 to your computer and use it in GitHub Desktop.
Save fractalatcarf/1f773e613c32210672eb8ab36b535a78 to your computer and use it in GitHub Desktop.
live code du soir
require 'date'
DEPTS = {
13 => "Bouches du Rhone",
84 => "Vauclause"
}
def parse_nss(nss)
match = nss.match(/^(?<sex>1|2) ?(?<year>\d{2}) ?(?<month>\d{2}) ?(?<dept>\d{2}) ?\d{3} ?\d{3}$/)
return "invalid ssn" if match.nil?
"#{match[:sex] == '1' ? "male" : "female"}, born #{Date::MONTHNAMES[match[:month].to_i]} #{match[:year]} in #{DEPTS[match[:dept].to_i]}"
end
puts parse_nss("1 80 02 13 123 456")
# male, born February 80 in BDR
puts parse_nss("2820984123456")
# female, born September 82 in Vaucluse
puts parse_nss("3000")
# invalide ssn
def add_figures(figures)
return figures.to_i if figures.length == 1
return figures[0].to_i + add_figures(figures[1..-1])
# sum = 0
# figures.length.times do |i|
# sum += figures[i].to_i
# end
# return sum
end
puts add_figures("12934")
MESSAGE = "bonjour %s, comment ça va ? ton nom de famille est %s"
def say_hello(first_name, last_name)
MESSAGE % [first_name, last_name]
end
puts say_hello("Damien", "Vincent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment