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
FROM ruby:2.7.1-alpine | |
ENV BUNDLER_VERSION=2.1.4 | |
RUN apk add --update --no-cache \ | |
binutils-gold \ | |
build-base \ | |
curl \ | |
file \ | |
g++ \ |
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
# str = "3x + 2 + x/6 = 5", expected: 0.94736 | |
# str = "3x = 9", expected: 3.0 | |
# str = '3x - 2 + x/6 = 5', expected: 2.21 | |
# program to solve linear equation with arg as str format of linear eqn. | |
def linear_equation(str) | |
elements = str.split(' ') | |
nums = [] | |
xs = [] | |
signs = ['+', "-"] | |
next_sign = 1 |
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
# Expected arg to be 2-d array and each sub array to have 2 numbers representing range-start and range-end | |
# [[1, 4], [6, 6], [6, 8], [1, 10]], expected: [[1, 10]] | |
# program to solve finding the overlapping ranges and combining them. | |
def range_flatten(arr) | |
res = []; done = [] | |
arr.each_with_index do |range, i| | |
a = range.first; b = range.second | |
arr[(i+1)..-1].each_with_index do |other_range, j| | |
next if done.include?(i+j+1) | |
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 factorial(n) | |
return 1 if n==1 | |
n*factorial(n-1) | |
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 custom_flat (arr, res = []) | |
arr.each_with_index do |ele, i| | |
if arr[i].class.name == "Array" | |
#p "ARR - #{arr[i]}" | |
custom_flat arr[i], res | |
else | |
#p "ELE - #{arr[i]}" | |
res << arr[i] | |
#p res | |
end |