Skip to content

Commit

Permalink
Merge branch 'main' into DNF-Algo
Browse files Browse the repository at this point in the history
  • Loading branch information
damarudhvarma authored Oct 22, 2024
2 parents 85f96a7 + e6da9b5 commit 721d820
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 52 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/autocomment-iss-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const greetingMessage = `Hi @${issueCreator} πŸ‘‹, your issue #${issueNumber} has been successfully closed βœ…. Thank you for your valuable contribution! πŸ™Œ`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
37 changes: 37 additions & 0 deletions .github/workflows/close-old-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Close Old Issues
on:
schedule:
- cron: "0 0 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Close Old Issues
run: |
open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues?state=open" \
| jq -r '.[] | .number')
for issue in $open_issues; do
# Get the last updated timestamp of the issue
last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \
| jq -r '.updated_at')
days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 ))
if [ $days_since_update -gt 15 ]; then
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"state":"closed"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue"
# Add a comment explaining when the issue will be closed
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"body":"This issue has been automatically closed due to inactivity for over 15 days. If you think it's still important, feel free to reopen it or submit a new issue. Thank you! 😊"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments"
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
@${{ github.event.pull_request.user.login }} Hurray, your PR got merged into our SkillShow πŸ₯³. Thanks a bunch. Feel free to take another Issue. πŸ’–
@${{ github.event.pull_request.user.login }} Hurray, your PR got merged into our Skill-Show πŸ₯³. Thanks a bunch. Feel free to take another Issue. πŸ’–
4 changes: 4 additions & 0 deletions Beginner Level πŸ“/Circle/Answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function curcumfrence(r){
console.log(Math.PI * r*r)
}
curcumfrence(prompt("Please enter a number "))
22 changes: 22 additions & 0 deletions Beginner Level πŸ“/Circle/Problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Problem Description
Aryan is a small kid, and the circle is his favorite shape. Whenever he gets a number, he tries to find the area of a circle whose radius is that given number.

You are given a number `r` as an argument denoting the radius of the circle. You need to implement the function `findAreaOfCircle` which will return a number equal to the area of the circle with radius `r`. Given radius is always greater than 0.

**Hint 1:** The area of a circle is calculated using the formula: `Area = Ο€ * r * r` (where `r` is the radius of the circle).

**Hint 2:** Use `Math.PI` to get the value of pi.


## Sample Input
```plaintext
3
```

## Sample Output
```plaintext
28.274333882308138
```

**Explanation:**
Area of the circle = `Math.PI * 3 * 3 = 28.274333882308138`
40 changes: 40 additions & 0 deletions Beginner Level πŸ“/Grid Maximum Path Sum/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int maxPathSum(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
vector<vector<int>> dp(m, vector<int>(n, 0));

dp[0][0] = grid[0][0];

for (int i = 1; i < m; ++i)
dp[i][0] = dp[i-1][0] + grid[i][0];

for (int j = 1; j < n; ++j)
dp[0][j] = dp[0][j-1] + grid[0][j];

for (int i = 1; i < m; ++i) {
for (int j = 1; j < n; ++j) {
dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + grid[i][j];
}
}

return dp[m-1][n-1];
}

int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> grid(m, vector<int>(n));

for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
cin >> grid[i][j];

cout << maxPathSum(grid) << endl;

return 0;
}
38 changes: 38 additions & 0 deletions Beginner Level πŸ“/Grid Maximum Path Sum/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Grid Maximum Path Sum

You are given a 2D grid of size `m x n` containing non-negative integers. You need to find a path from the top-left corner to the bottom-right corner that maximizes the sum of all the numbers along its path. You can only move either right or down at any point in time.

#### Input:

- The first line contains two integers `m` and `n` representing the number of rows and columns in the grid, respectively.
- The next `m` lines contain `n` integers each, representing the grid values.

#### Output:

- Output a single integer representing the maximum sum that can be obtained by following a path from the top-left to the bottom-right of the grid.

#### Constraints:

- `1 <= m, n <= 100`
- `0 <= grid[i][j] <= 1000`

#### Example:

**Input:**

```
3 3
1 3 1
1 5 1
4 2 1
```

**Output:**

```
12
```

**Explanation:**

The path with the maximum sum is: `1 β†’ 3 β†’ 5 β†’ 2 β†’ 1`, resulting in a total sum of 12.
86 changes: 37 additions & 49 deletions Beginner Level πŸ“/Password Strength Checker/solution.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,42 @@
password = input("Enter a password: ")
def check_password_strength():
try:
password = input("Enter a password: ")

# Check the length of the password
length = len(password)
# Check if the password is empty
if not password:
raise ValueError("Password cannot be empty.")

# Initialize
has_upper = False
has_lower = False
has_digit = False
has_symbol = False
# Check the length of the password
length = len(password)

# Loops each character in password to check
for char in password:
if 'a' <= char <= 'z':
# Checks for lowercase
has_lower = True
elif 'A' <= char <= 'Z':
# Checks for uppercase
has_upper = True
elif "0" <= char <= '9':
# Checks for digit
has_digit = True
else:
# Checks for symbol
has_symbol = True
# Initialize character type flags
has_upper = any(char.isupper() for char in password)
has_lower = any(char.islower() for char in password)
has_digit = any(char.isdigit() for char in password)
has_symbol = any(not char.isalnum() for char in password)

# Logic conditons
if length < 6:
# Less than 6 characters
ans = "weak"
elif length >= 6 and length <= 10:
# between 6 and 10 characters
if (has_lower and has_upper) or (has_digit and (has_lower or has_upper)):
# Contains lowercase and uppercase letters or both letters and digits
ans = "moderate"
elif has_lower and not has_upper and not has_digit and not has_symbol:
# Contains only lowercase letters
ans = "weak"
elif has_digit and not has_lower and not has_upper and not has_symbol:
# Contains only digits
ans = "weak"
else:
ans = "weak"
elif length > 10:
# Longer than 10 characters
if (has_lower and has_upper) or (has_digit and (has_lower or has_upper)):
ans = "moderate"
elif has_lower and has_upper and has_digit and has_symbol:
# Contains lowercase, uppercase, digits, and special characters
ans = "strong"
else:
ans = "weak"
# Determine password strength
if length < 6:
ans = "weak"
elif 6 <= length <= 10:
if (has_lower and has_upper) or (has_digit and (has_lower or has_upper)):
ans = "moderate"
else:
ans = "weak"
else: # length > 10
if has_lower and has_upper and has_digit and has_symbol:
ans = "strong"
elif (has_lower and has_upper) or (has_digit and (has_lower or has_upper)):
ans = "moderate"
else:
ans = "weak"

print(f'Your password is {ans}.')
print(f'Your password is {ans}.')

except ValueError as ve:
print(f"Error: {ve}")
except Exception as e:
print(f"An unexpected error occurred: {e}")

# Call the function to execute the password strength check
check_password_strength()
34 changes: 34 additions & 0 deletions Beginner Level πŸ“/Roman to Integer/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
Given a roman numeral, convert it to an integer.

Example 1:

Input: s = "III"
Output: 3
Explanation: III = 3.
Example 2:

Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.
Example 3:

Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
19 changes: 19 additions & 0 deletions Beginner Level πŸ“/Roman to Integer/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public int romanToInt(String s) {
int sol=0, num=0;
for (int i=s.length()-1; i>=0; i--) {
switch(s.charAt(i)) {
case 'I': num=1; break;
case 'V': num=5; break;
case 'X': num=10; break;
case 'L': num=50; break;
case 'C': num=100; break;
case 'D': num=500; break;
case 'M': num=1000; break;
}
if (4*num<sol) sol-=num;
else sol+=num;
}
return sol;
}
}
20 changes: 20 additions & 0 deletions Beginner Level πŸ“/Shortest Path/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Find the Shortest Path in a Weighted Graph

You are given a weighted graph with 5 nodes (A, B, C, D, E) and the following edges:

| From | To | Weight |
|------|----|--------|
| A | B | 4 |
| A | C | 2 |
| B | C | 1 |
| B | D | 5 |
| C | D | 3 |
| C | E | 2 |
| D | E | 1 |

Find the shortest path from node A to node E using Dijkstra's algorithm.

**Requirements:**
1. Implement Dijkstra's algorithm in Python.
2. Use a priority queue to efficiently select the next node.
3. Return the shortest path and its total weight.
46 changes: 46 additions & 0 deletions Beginner Level πŸ“/Shortest Path/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import heapq

def dijkstra(graph, start, end):
distances = {node: float('inf') for node in graph}
distances[start] = 0
previous = {node: None for node in graph}
queue = [(0, start)]

while queue:
current_distance, current_node = heapq.heappop(queue)

if current_distance > distances[current_node]:
continue

for neighbor, weight in graph[current_node].items():
distance = current_distance + weight

if distance < distances[neighbor]:
distances[neighbor] = distance
previous[neighbor] = current_node
heapq.heappush(queue, (distance, neighbor))

path = []
current_node = end
while current_node:
path.append(current_node)
current_node = previous[current_node]

return path[::-1], distances[end]


# Define the graph
graph = {
'A': {'B': 4, 'C': 2},
'B': {'C': 1, 'D': 5},
'C': {'D': 3, 'E': 2},
'D': {'E': 1},
'E': {}
}

start_node = 'A'
end_node = 'E'

shortest_path, total_weight = dijkstra(graph, start_node, end_node)
print(f"Shortest path: {' -> '.join(shortest_path)}")
print(f"Total weight: {total_weight}")
Loading

0 comments on commit 721d820

Please sign in to comment.