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 from_binary(number) | |
| number_array = number.to_s.chars.reverse | |
| returning = 0 | |
| number_array.each_with_index do |item, i| | |
| location = 2 ** i | |
| returning += (location * item.to_i) | |
| end | |
| returning | |
| 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
| class RPNCalculator | |
| attr_accessor :calculator | |
| def initialize | |
| @stack = [] | |
| @value = 0 | |
| end | |
| def push(number) | |
| @stack << number |
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 into_words(num) | |
| ones = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] | |
| teens = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] | |
| tens = ["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] | |
| if num == 0 | |
| return "zero" | |
| elsif num % 10 == 0 && num < 100 | |
| return tens[(num / 10) - 1] | |
| elsif num < 20 |
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
| skippers = GlobalCohort.new("Fiery Skippers", Date.parse("8-February-2016")) | |
| # => #<GlobalCohort:0x007f956c09bc40 @local_cohorts=[], @students=[], @name="Fiery Skippers", @p0_start_date=#<Date: 2016-03-08 ((2457456j,0s,0n),+0s,2299161j)>> | |
| nyc = LocalCohort.new("New York", skippers) | |
| chicago = LocalCohort.new("Chicago", skippers) | |
| sanfran = LocalCohort.new("San Francisco", skippers) | |
| skippers.add_local_cohort(nyc) | |
| skippers.add_local_cohort(chicago) | |
| skippers.add_local_cohort(sanfran) |
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 Student < LocalCohort | |
| attr_reader :student_name, :email, :history, :local_cohort | |
| def initialize(student_name, email, local_cohort) | |
| @student_name, @email, @local_cohort = student_name, email, local_cohort | |
| @history = [] | |
| end | |
| def grade | |
| events = history.select{|event| event[1].is_a?(Fixnum)} |
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 LocalCohort < GlobalCohort | |
| attr_reader :city, :students, :global_cohort | |
| def initialize(city, global_cohort) | |
| @city, @global_cohort = city, global_cohort | |
| @students = [] | |
| end | |
| def global_cohort_name | |
| global_cohort.name |
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 'date' | |
| class GlobalCohort | |
| attr_reader :local_cohorts, :name, :p0_start_date | |
| def initialize(name, p0_start_date=nil) | |
| @local_cohorts = [] | |
| @students = [] | |
| @name = name | |
| @p0_start_date = p0_start_date.nil? ? Date.today : p0_start_date |
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(array, item) | |
| index = nil | |
| found = false | |
| mid_point = array.length / 2 | |
| before = 0 | |
| after = 0 | |
| while found == false | |
| if array.length < 2 || array[mid_point] == item |