This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########################## | |
| # => factorial iterative | |
| ########################## | |
| def factorial_it(n) | |
| return (1..n).inject(:*) | |
| end | |
| #puts factorial(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # actual funtion to get the prime factors | |
| def prime_factors(n) | |
| primes = [] | |
| until n == 1 | |
| primes << prime_number(n) | |
| n /= primes.last | |
| puts "primes_array:#{primes.inspect} | n:#{n}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def birthday_timestamp(yyyy,mm,dd) | |
| Time.new(yyyy,mm,dd) | |
| end | |
| #birthday_timestamp | |
| def age(yyyy,mm,dd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # # Determine whether a string contains a Social Security number. | |
| def has_ssn?(string) | |
| /\d{3}-\d{2}-\d{4}/.match(string) | |
| end | |
| # Return the Social Security number from a string. | |
| def grab_ssn(string) | |
| string[/\d{3}-\d{2}-\d{4}/] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def binary_search(num, array) | |
| return -1 if !array.include?(num) | |
| index = (array.length)/2 | |
| index_array = [(array.length), 0] | |
| until num == array[index] | |
| index = (index_array[0] + index_array[1])/2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $numbers_hash = {1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eigth", 9 => "nine", 10 => "ten", | |
| 10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "forteen", 15 => "fifteen", 16 => "sixteen", 17 => "seventeen", | |
| 18 => "eighteen", 19 => "nineteen", 20 => "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", | |
| 80 => "eighty", 90 => "ninty", 100 => "hundred", 1_000 => "thousand", 1_000_000 => "million", 1_000_000_000 => "billion", | |
| 1_000_000_000_000 => "trillion"} | |
| def ransom_below_100(number,modifier,result) | |
| quotient,remainder = number.divmod(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Peggie | Bernier | (598)-885-3990 | georgianna.casper@emardvolkman.org | |
|---|---|---|---|---|
| Ines | Roberts | (717)-629-5254 | alanis.hane@bayer.com | |
| Carley | Luettgen | (153)-754-3308 | jeramy_terry@kerluke.org | |
| Evie | Bashirian | (684)-662-7552 | herminia_jewe@schumm.biz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hospital | |
| attr_accessor :name, :employees, :patients | |
| def initialize(name, location) | |
| @name, @location, @employees, @patients = name, location, [], [] | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'yaml' | |
| class TodoList < Hash | |
| def initialize(file_name) | |
| @file_name = file_name | |
| File.open( @file_name, 'w' ) { |file| YAML.dump( self, file )} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'optparse' | |
| options = {date: false, sort: false, ddate: false, tag: false, prio: false} | |
| optparse = OptionParser.new do|opts| | |
| opts.on("--date") do | |
| options[:date] = true | |
| end | |
| opts.on('--sort') do |
OlderNewer