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
#!/bin/bash | |
# Above line to specify which shell to be used to execute the program | |
echo "Enter first Number" # echo used to print the message to screen | |
read first_number # read and store the input from terminal | |
echo "enter second Number" | |
read second_number | |
sum=`expr $first_number + $second_number` # things insed the backtick ` are evaluate or executed | |
echo "$first_number + $second_number = $sum" # $ to specify arguments |
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
#!/bin/bash | |
# above line used to specify which shell to be used to execute the program | |
add() # function to add 2 numbers | |
{ | |
num1=$1 | |
num2=$2 | |
sum=`expr $num1 + $num2` # things insed the backtick `are evaluate or executed | |
echo "$num1 + $num2 = $sum" | |
} |
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
require './my_aws_helper' | |
class AwsDemo | |
include MyAwsHelper | |
def start_execution | |
p '1. Bucket Details, 2. Create Bucket 3. Upload To Bucket' | |
choice = gets.chomp.to_i | |
start_user_interaction(choice) | |
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
require 'zip' | |
input_directory = '' # directory to be zipped | |
zipfile_name = '' # zip-file name | |
# zip a folder with only files (NO SUB FOLDERS) | |
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| | |
Dir[File.join(input_directory, '*')].each do |file| | |
zipfile.add(file.sub(input_directory, ''), file) | |
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
class Solution | |
def solution(array) | |
left_part = array[0] | |
right_part = array.sum - left_part | |
diff = (left_part - right_part).abs | |
total = array.length | |
array.each_with_index do |element, index| | |
next if index == 0 |
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 CyclicRotation | |
def solution(array, num) | |
new_array = Array.new(array.length) | |
array.each_with_index do |element, idx| | |
# (index + element) % array_size will give new index value to which we have to insert current value | |
new_array[(idx + num) % array.length] = element | |
end | |
new_array |
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 BracketDemo | |
def solution(str) | |
valid = true | |
stack = [] | |
str.each_char do |char| | |
case char | |
when '[', '{', '(' | |
stack.push(char) | |
when ']' |
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 Fish | |
def solution(weights, direction) | |
stack = [] | |
survivor_count = 0 | |
weights.each_with_index do |elem, idx| | |
if direction[idx] == 1 | |
stack.push(elem) | |
else | |
if stack.empty? |
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 Dominator | |
def solution(a) | |
counter = 0 | |
candidate = 0 | |
a.each do |elem| | |
if counter == 0 | |
candidate = elem | |
counter += 1 | |
elsif candidate == elem |
OlderNewer