Skip to content

Instantly share code, notes, and snippets.

View mindplace's full-sized avatar
🎯
Focusing

Esther Leytush mindplace

🎯
Focusing
View GitHub Profile
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
class RPNCalculator
attr_accessor :calculator
def initialize
@stack = []
@value = 0
end
def push(number)
@stack << number
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
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)
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)}
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
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
def get_range(max)
range = [0, 0, 2]
(3..max).each do |num|
num.odd? ? (range << num) : (range << 0)
end
range
end
def sum_of_primes(max)
range = get_range(max)
function nthPrimeNumber(num) {
var primes = [0, 0, 2];
var max = Math.pow(10, 4);
for (var i=3; i < max + 1; i++) {
if (i % 2 == 0) {
primes.push(0);
} else {
primes.push(i);
}
}
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