This file contains 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 subsets(array) | |
subsets = [] | |
array.each do |elem| | |
new = subsets.inject([]) { |accum, n| accum << n.dup.push(elem) } | |
subsets.concat(new) | |
subsets << [elem] | |
end | |
subsets | |
end |
This file contains 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
## Allows runner to run all commands | |
runner ALL=(ALL) ALL |
This file contains 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 parse_var(text) | |
if text.include?(",") | |
return test.split(",") | |
elsif text.include?(",") | |
return test.split(";") | |
else | |
[text] | |
end | |
end |
This file contains 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 eulers_method(range, h, t, y, &block) | |
calculations = [] | |
calculations << [t, y] | |
while t <= range.last | |
slope = yield(t, y) | |
yn = y + (slope * h) | |
y = yn | |
t += h | |
calculations << [t, yn] | |
end |
This file contains 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 find_largest_product(matrix) | |
matrix = matrix.map { |array| array.map(&:to_i) } | |
sum = 0 | |
0.upto(16) do |i| | |
0.upto(16) do |j| | |
m4x4 = extract_4x4_at(i, j, matrix) | |
candidate_sum = find_4x4_sum(m4x4) | |
sum = candidate_sum if candidate_sum > sum | |
end |
This file contains 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 truncated_subsets(prime): | |
if len(prime) == 1: return [prime] | |
subsets = [] | |
for i in range(1, len(prime)): | |
subsets.append(prime[i:len(prime)]) | |
subsets.append(prime[0:len(prime)-i]) | |
return subsets | |
def is_truncatable_prime(prime, primes): | |
subsets = truncated_subsets(prime) |
This file contains 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 NxNGrid | |
class Node | |
attr_accessor :paths | |
def initialize(pos) | |
@pos = pos | |
end | |
def to_i |
This file contains 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 update_confirm | |
@eft = Eft.find_latest_unconfirmed_edit(@user.student_id) | |
@eft || (redirect_to(eft_url) && return) | |
if params[:confirm] | |
@eft.update_attribute(:confirm_flag, true) ##### @eft.updated_at doesn't get updated ##### | |
Notifier.deliver_confirmation_for_student(@eft.email_address) if Rails.env == "production" && session[:admin_uid].nil? | |
audit_notification() | |
redirect_to(completed_eft_url) | |
else |
This file contains 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 update_confirm | |
@eft = Eft.find_latest_unconfirmed_edit(@user.student_id) | |
@eft || (redirect_to(eft_url) && return) | |
if params[:confirm] | |
@eft.update_attribute(:confirm_flag, true) | |
@eft.touch() ##### Now @eft.updated_at gets updated ##### | |
Notifier.deliver_confirmation_for_student(@eft.email_address) if Rails.env == "production" && session[:admin_uid].nil? | |
audit_notification() | |
redirect_to(completed_eft_url) |
This file contains 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 TestObject | |
def method_missing(message, *args, &block) | |
if !self.respond_to?(message) && message[/=/] | |
self.class.send(:attr_accessor, message[0...-1]) | |
self.send(message, args[0]) | |
else | |
super | |
end | |
end | |
end |
OlderNewer