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 hanoi(n, source, intermediary, destination) | |
if n > 0 | |
hanoi(n-1, source,destination,intermediary) | |
destination.push(source.pop) | |
hanoi(n-1, intermediary, source, destination) | |
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
def find_tree_sum(start, sum) | |
$last_sum ||= 0 | |
$result ||= [] | |
if start.nil? | |
return false | |
end | |
$last_sum += start.value | |
$result << start.value |
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 insert(a, index, value) | |
i = index | |
while(index >= 0 && value < a[i]) | |
a[i+1] = a[i] | |
i -= 1 | |
end | |
a[i+1] = value | |
end | |
def selection_sort(a) |
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
a = [ | |
[0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0], | |
[0,0,0,0] | |
] | |
def is_safe(a, row, col, n) | |
#Check the same row |
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 Activity | |
attr_accessor :s, :f | |
def initialize(s,f) | |
@s = s | |
@f = f | |
end | |
def inspect | |
"#{s} to #{f}" | |
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
def permutations(str, prefix) | |
if str.length == 0 | |
puts prefix | |
else | |
(0).upto(str.length-1) do |i| | |
permutations(str.slice(0,i)+str.slice(i+1, str.length), prefix + str[i]) | |
end | |
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
# Iterative using visited attribute | |
def in_order_ite | |
s = Stack.new | |
s.push root | |
until s.empty? | |
c = s.last | |
if c.left && !c.left.visited |
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
w = [10, 20, 30] | |
b = [60, 100, 120] | |
$result = {} | |
def knaspask(w, b, n, max_w) | |
if n == 0 || max_w == 0 | |
result = 0 | |
else | |
if result = $result["#{n.to_s}-#{max_w.to_s}"] |
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
# Write your query or mutation here | |
mutation { | |
extractLabResults(documents: [ | |
{ | |
url: "https://app-staging.trymeasured.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTU2NTYsInB1ciI6ImJsb2JfaWQifX0=--e86debef406abc972833b0f141d8f453d0eedede/Lacey%20Frost_Quest%20Lab%20Results%20(1).pdf?disposition=attachment", | |
extension: "pdf" | |
}, | |
{ | |
url: "https://app-staging.trymeasured.com/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTU3MDAsInB1ciI6ImJsb2JfaWQifX0=--3e74cba16816412fb2d5c9c3d75f5a3c562cbec1/trig%20(3).png?disposition=attachment", | |
extension: "png" |
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 PriorityQueue | |
attr_accessor :a | |
attr_accessor :size | |
def initialize(a) | |
@a = a | |
self.size = a.length | |
build_heap | |
end |