Skip to content

Commit d2c2f74

Browse files
committed
Updated
1 parent ebc3168 commit d2c2f74

File tree

11 files changed

+206
-0
lines changed

11 files changed

+206
-0
lines changed

AWS_BedRock/test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
my_list = [1, 2, 3]
2+
my_list.append(4)
3+
print(my_list) # Output: [1, 2, 3, 4]
4+
5+
# Appending another list as an element
6+
another_list = [5, 6, 7]
7+
my_list.append(another_list)
8+
print(my_list) # Output: [1, 2, 3, 4, [5, 6, 7]]
9+
10+
my_list = [1, 2, 3]
11+
another_list = [4, 5, 6]
12+
13+
my_list.extend(another_list)
14+
print(my_list) # Output: [1, 2, 3, 4, 5, 6]
15+
16+
# Extend with a string (iterable)
17+
my_list.extend("hello")
18+
print(my_list) # Output: [1, 2, 3, 4, 5, 6, 'h', 'e', 'l', 'l', 'o']

AWS_BedRock/test2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def bubble_sort(arr):
2+
n = len(arr)
3+
4+
# Traverse through all array elements
5+
for i in range(n):
6+
# Last i elements are already in place
7+
for j in range(0, n-i-1):
8+
# Traverse the array from 0 to n-i-1
9+
# Swap if the element found is greater than the next element
10+
if arr[j] > arr[j+1]:
11+
arr[j], arr[j+1] = arr[j+1], arr[j]
12+
13+
# Example usage:
14+
arr = [64, 34, 25, 12, 22, 11, 90]
15+
bubble_sort(arr)
16+
print("Sorted array is:", arr)

Advance_bash_scripting/1.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Print a welcome message
4+
echo "Welcome to the Advanced Bash Scripting Interview Preparation Script!"
5+
echo "Let's get started..."
6+
7+
# Check if the script is running as root
8+
if [ "$(id -u)" != "0" ]; then
9+
echo "This script must be run as root"
10+
exit 1
11+
fi
12+
13+
# Print the current date and time
14+
echo "Current date and time: $(date)"
15+
16+
# Print the system information
17+
echo "System information:"
18+
uname -a
19+
20+
# List all installed packages
21+
echo "Installed packages:"
22+
if command -v dpkg &> /dev/null; then
23+
dpkg --list
24+
elif command -v rpm &> /dev/null; then
25+
rpm -qa
26+
else
27+
echo "Unable to determine package manager"
28+
fi
29+
30+
# Check the disk space
31+
echo "Disk space:"
32+
df -h
33+
34+
# Check the memory usage
35+
echo "Memory usage:"
36+
free -m
37+
38+
# Print a closing message
39+
echo "Script execution completed. Goodbye!"

Advance_bash_scripting/2.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Create a directory if it doesn't exist
4+
mkdir -p /path/to/directory
5+
6+
# Check if a file exists
7+
if [ -f "/path/to/file" ]; then
8+
echo "File exists"
9+
else
10+
echo "File does not exist"
11+
fi
12+
13+
# List files in a directory
14+
echo "Files in directory:"
15+
ls /path/to/directory
16+
17+
# Count the number of files in a directory
18+
file_count=$(ls /path/to/directory | wc -l)
19+
echo "Number of files: $file_count"

Advance_bash_scripting/3.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Search for a pattern in a file
4+
grep "pattern" /path/to/file
5+
6+
# Replace a string in a file
7+
sed -i 's/old_string/new_string/g' /path/to/file
8+
9+
# Count the number of occurrences of a word in a file
10+
word_count=$(grep -o "word" /path/to/file | wc -l)
11+
echo "Number of occurrences of 'word': $word_count"

Advance_bash_scripting/4.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Loop through numbers and print them
4+
for i in {1..5}; do
5+
echo "Number: $i"
6+
done
7+
8+
# Check if a number is even or odd
9+
number=6
10+
if [ $((number % 2)) -eq 0 ]; then
11+
echo "$number is even"
12+
else
13+
echo "$number is odd"
14+
fi

Advance_bash_scripting/5.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Define a function
4+
hello() {
5+
echo "Hello, world!"
6+
}
7+
8+
# Call the function
9+
hello
10+
11+
# Function with arguments
12+
greet() {
13+
echo "Hello, $1!"
14+
}
15+
16+
# Call the function with an argument
17+
greet "John"

Advance_bash_scripting/6.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Initialize a variable
4+
counter=0
5+
6+
# Loop that always executes at least once
7+
while true; do
8+
# Increment the counter
9+
((counter++))
10+
11+
# Print the counter value
12+
echo "Counter: $counter"
13+
14+
# Check if the counter reaches a certain value
15+
if [ $counter -eq 5 ]; then
16+
break # Exit the loop when the condition is met
17+
fi
18+
done

Advance_bash_scripting/7.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Define the bubble sort function
4+
bubble_sort() {
5+
# Store the array passed as argument
6+
arr=("$@")
7+
8+
# Get the length of the array
9+
n=${#arr[@]}
10+
11+
# Perform the bubble sort algorithm
12+
for ((i = 0; i < n-1; i++)); do
13+
for ((j = 0; j < n-i-1; j++)); do
14+
if ((arr[j] > arr[j+1])); then
15+
# Swap the elements
16+
temp=${arr[j]}
17+
arr[j]=${arr[j+1]}
18+
arr[j+1]=$temp
19+
fi
20+
done
21+
done
22+
23+
# Print the sorted array
24+
echo "Sorted array: ${arr[@]}"
25+
}
26+
27+
# Example usage:
28+
numbers=(64 34 25 12 22 11 90)
29+
echo "Original array: ${numbers[@]}"
30+
bubble_sort "${numbers[@]}"

Advance_bash_scripting/test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from collections import defaultdict
2+
3+
def find_anagrams(words):
4+
# Create a defaultdict to store anagrams
5+
anagrams = defaultdict(list)
6+
7+
# Iterate through each word in the list
8+
for word in words:
9+
# Sort the characters in the word
10+
sorted_word = ''.join(sorted(word))
11+
12+
# Add the word to the list of anagrams with the sorted word as key
13+
anagrams[sorted_word].append(word)
14+
15+
# Filter out non-anagram groups
16+
return [group for group in anagrams.values() if len(group) > 1]
17+
18+
# Example usage:
19+
word_list = ["listen", "silent", "hello", "world", "act", "cat", "dog", "god"]
20+
#out = [[],[]]
21+
anagram_groups = find_anagrams(word_list)
22+
print("Anagram groups:")
23+
24+
print(anagram_groups)

0 commit comments

Comments
 (0)