Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rainwater Problem#120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spandey1296 merged 36 commits intocoder2hacker:spandey1296-patch-1fromkashyap-singh:main
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
36 commits
Select commitHold shift + click to select a range
4aaa111
Added array right rotated logic
Peeyush19999Oct 2, 2022
3bbd628
Hill_Cipher.java
harshitgupta2000Oct 2, 2022
904320e
Caesar_cipher.py
harshitgupta2000Oct 2, 2022
53193d4
KMP.java
harshitgupta2000Oct 2, 2022
786583f
Heap_sort.java
harshitgupta2000Oct 2, 2022
6ff4d61
feat: Added personal content
godsakaniOct 2, 2022
eeb4102
Added solution using filter and includes
Peeyush19999Oct 2, 2022
1e3e36a
Create SnakeGame.py
gauravtrivedi967Oct 2, 2022
b2fd605
Create CreditRisk.py
gauravtrivedi967Oct 2, 2022
4f0c7b3
Create ChatBot.py
gauravtrivedi967Oct 2, 2022
1308e9b
Create HindiDataCleaning.py
gauravtrivedi967Oct 2, 2022
3e65cb5
Merge pull request #107 from gauravtrivedi967/patch-3
SirajmollaOct 2, 2022
58790b0
Merge pull request #108 from gauravtrivedi967/patch-4
SirajmollaOct 2, 2022
d9e05bf
Merge pull request #106 from gauravtrivedi967/patch-2
SirajmollaOct 2, 2022
ab70cf3
Merge pull request #105 from gauravtrivedi967/patch-1
SirajmollaOct 2, 2022
b1e2d3e
Merge pull request #104 from Peeyush19999/patch-2
SirajmollaOct 2, 2022
4a7ff4d
Merge pull request #103 from kashyap-singh/main
SirajmollaOct 2, 2022
baa1c96
Merge pull request #102 from godsakani/hacktoberfes
SirajmollaOct 2, 2022
95918a2
Merge pull request #101 from kashyap-singh/main
SirajmollaOct 2, 2022
3e0bda5
Merge pull request #100 from kashyap-singh/main
SirajmollaOct 2, 2022
6958b76
Merge pull request #98 from kashyap-singh/main
SirajmollaOct 2, 2022
1f79665
Merge pull request #97 from harshitgupta2000/patch-3
SirajmollaOct 2, 2022
63e795c
Merge pull request #96 from harshitgupta2000/patch-2
SirajmollaOct 2, 2022
d3584bc
Merge pull request #95 from harshitgupta2000/patch-1
SirajmollaOct 2, 2022
9b016f4
Merge pull request #94 from harshitgupta2000/main
SirajmollaOct 2, 2022
1d27e3b
Merge pull request #93 from Peeyush19999/patch-1
SirajmollaOct 2, 2022
a20f9ce
Create Detect Capital
bishalp22Oct 2, 2022
b3215cc
Added a java program to reverse an array
aphsaviiOct 2, 2022
9b507b7
Merge pull request #114 from coder2hacker/spandey1296-patch-1
SirajmollaOct 2, 2022
45bb213
Merge pull request #113 from coder2hacker/spandey1296-patch-3
SirajmollaOct 2, 2022
02da43e
Merge pull request #112 from coder2hacker/spandey1296-patch-4
SirajmollaOct 2, 2022
502ce55
Merge pull request #111 from aphsavii/main
SirajmollaOct 2, 2022
32fa732
Merge pull request #110 from coder2hacker/spandey1296-patch-2
SirajmollaOct 2, 2022
03733eb
Merge pull request #109 from bishalp22/patch-5
SirajmollaOct 2, 2022
03c47d6
Add files via upload
kashyap-singhOct 2, 2022
674a2a5
Add files via upload
kashyap-singhOct 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions07 rainwater-trap.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <vector>
using namespace std;


int trappedWater(vector<int> heights) {
int n = heights.size();
if(n<=2){
return 0;
}
vector<int> left(n,0), right(n,0);
left[0] = heights[0];
right[n-1] = heights[n-1];

for(int i=1;i<n;i++){
left[i] = max(left[i-1],heights[i]);
right[n-i-1] = max(right[n-i],heights[n-i-1]);
}
int water = 0;
for(int i=0;i<n;i++){
water += min(left[i],right[i]) - heights[i];
}
return water;
}

int main() {
int n;
cin>>n;
vector<int> water;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
water.push_back(a);
}
cout<<trappedWater(water)<<endl;
return 0;
}
110 changes: 110 additions & 0 deletionsChatBot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
#%%
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].id)


def speak(audio):
engine.say(audio)
engine.runAndWait()


def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")

elif hour>=12 and hour<18:
speak("Good Afternoon!")

else:
speak("Good Evening!")

speak("I am Lucifer Sir. Please tell me how may I help you")

def takeCommand():
#It takes microphone input from the user and returns string output

r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)

try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")

except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query

def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('youremail@gmail.com', 'your-password')
server.sendmail('youremail@gmail.com', to, content)
server.close()

if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = takeCommand().lower()

# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)

elif 'open youtube' in query:
webbrowser.open("youtube.com")

elif 'open google' in query:
webbrowser.open("google.com")

elif 'open stackoverflow' in query:
webbrowser.open("stackoverflow.com")


elif 'play music' in query:
music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))

elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")

elif 'open code' in query:
codePath = "C:\\Users\\GAURAV\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)

elif 'email to harry' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "harryyourEmail@gmail.com"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry my friend gaurav. I am not able to send this email")
116 changes: 116 additions & 0 deletionsCreditRisk.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
#%%
import warnings
warnings.filterwarnings('ignore')

import os
import numpy as np
import pandas as pd
import scipy.stats as st
import statsmodels.api as sm
import matplotlib.pyplot as plt

from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score, confusion_matrix, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
# %%
os.chdir('D:/machine_learning/DATA_SET/credit_risk')
df_a = pd.read_csv('credit_risk.csv')
df_a.head()
# %%
df_a.isnull().sum()
# %%
df_a.dropna(axis=0,inplace=True)
df_a.isnull().sum()
# %%
df_a.dtypes
# %%
df_a["CoapplicantIncome"] = df_a["CoapplicantIncome"].astype('float')
df_a["ApplicantIncome"] = df_a["ApplicantIncome"].astype('float')
print("AFTER CHANGING INT & OBJECT TO FLOAT")
df_a.dtypes
# %%
df_a["Dependents"].value_counts()
# %%
cleanup_nums = {
"Married": {"Yes": 1, "No": 0},
"Self_Employed": {"Yes": 1, "No": 0},
"Property_Area": {"Rural":0, "Urban":1, "Semiurban":2},
"Education": {"Graduate": 1, "Not Graduate": 0},
"Loan_Status": { "Y": 1, "N": 0},
"Gender": { "Male": 1, "Female": 0},
"Dependents": { "0": 0, "1": 1, "2": 2, "3+": 3},
}

df_a.replace(cleanup_nums, inplace=True)
df_a.head()
# %%
df_corr = df_a[[ 'Gender', 'Married', 'Dependents', 'Education',
'Self_Employed', 'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
'Loan_Amount_Term', 'Credit_History', 'Property_Area','Loan_Status']]

df_corr.head()
# %%
plt.imshow(df_corr.corr(), cmap=plt.cm.Blues , interpolation='nearest')
cmap='coolwarm'
plt.colorbar()
tick_marks = [i for i in range(len(df_corr.columns))]
plt.xticks(tick_marks, df_corr.columns, rotation='vertical')
plt.yticks(tick_marks, df_corr.columns)
plt.show()
#%%
boolean_col = 'Loan_Status'
cols = ['Gender','Married','Dependents','Education','Self_Employed',
'ApplicantIncome', 'CoapplicantIncome', 'Credit_History'
]

xTrain = df_a[cols].values
yTrain = df_a[boolean_col].values
# %%
st.chisqprob = lambda chisq, df: st.chi2.sf(chisq, df)

model = sm.Logit( yTrain, xTrain )
result = model.fit()
result.summary( xname=cols, yname=boolean_col,title='Logit Model', alpha=1)
# %%
def calculate_accuracy( predictions, real):
correct = 0
for i in range(len(predictions)):
if round(predictions[i]) == round(real[i]):
correct += 1
return correct * 1.0 / len(predictions)
# %%
train_predictions = result.predict(xTrain)

train_accuracy = calculate_accuracy( train_predictions, yTrain )
print("Train Accuracy: ", train_accuracy * 100 )
# %%
train_predictions = (train_predictions > 0.5)

train_cm = confusion_matrix( yTrain, train_predictions, labels = [1.0, 0.0])
print(train_cm )
# %%
labels = ['0', '1']
cm = train_cm
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(cm, cmap='viridis')
plt.title('Confusion matrix')
fig.colorbar(cax)
ax.set_xticklabels([''] + labels)
ax.set_yticklabels([''] + labels)

r=0
c=0
for listItem in cm:
for cellItem in listItem:
ax.text(c,r, cellItem, va='center', ha='center', color='r')
c+=1
c=0
r+=1

plt.xlabel('Actual label')
plt.ylabel('Predicted label')
plt.show()
# %%
42 changes: 42 additions & 0 deletionsDetect Capital
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
Detect Capital
Level-Easy

We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the first letter in this word is capital, like "Google".
Given a string word, return true if the usage of capitals in it is right.
Example 1:
Input: word = "USA"
Output: true
Example 2:
Input: word = "FlaG"
Output: false
Constraints:
1 <= word.length <= 100
word consists of lowercase and uppercase English letters.

Time Complexity-o(n)
Space Complexity-o(1)

Java Solution

class Solution {
public boolean detectCapitalUse(String word) {
if(word.length()>=2 && word.charAt(0)>=97 && word.charAt(0)<=123 && word.charAt(1)>=65 && word.charAt(1)<=91)
return false;
for(int i=1;i<word.length()-1;i++){
if(word.charAt(i)>=65 && word.charAt(i)<=91){
if(word.charAt(i+1)>=65 && word.charAt(i+1)<=91);
else
return false;
}
else{
if(word.charAt(i+1)>=97 && word.charAt(i+1)<=123);
else
return false;
}
}
return true;
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp