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

Commit2b28ff2

Browse files
authored
Merge pull request#120 from kashyap-singh/main
Rainwater Problem
2 parents446c6ab +674a2a5 commit2b28ff2

15 files changed

+1070
-1
lines changed

‎07 rainwater-trap.cpp‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<iostream>
2+
#include<vector>
3+
usingnamespacestd;
4+
5+
6+
inttrappedWater(vector<int> heights) {
7+
int n = heights.size();
8+
if(n<=2){
9+
return0;
10+
}
11+
vector<int>left(n,0),right(n,0);
12+
left[0] = heights[0];
13+
right[n-1] = heights[n-1];
14+
15+
for(int i=1;i<n;i++){
16+
left[i] =max(left[i-1],heights[i]);
17+
right[n-i-1] =max(right[n-i],heights[n-i-1]);
18+
}
19+
int water =0;
20+
for(int i=0;i<n;i++){
21+
water +=min(left[i],right[i]) - heights[i];
22+
}
23+
return water;
24+
}
25+
26+
intmain() {
27+
int n;
28+
cin>>n;
29+
vector<int> water;
30+
for(int i=0;i<n;i++)
31+
{
32+
int a;
33+
cin>>a;
34+
water.push_back(a);
35+
}
36+
cout<<trappedWater(water)<<endl;
37+
return0;
38+
}

‎ChatBot.py‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#%%
2+
importpyttsx3#pip install pyttsx3
3+
importspeech_recognitionassr#pip install speechRecognition
4+
importdatetime
5+
importwikipedia#pip install wikipedia
6+
importwebbrowser
7+
importos
8+
importsmtplib
9+
10+
engine=pyttsx3.init('sapi5')
11+
voices=engine.getProperty('voices')
12+
# print(voices[1].id)
13+
engine.setProperty('voice',voices[0].id)
14+
15+
16+
defspeak(audio):
17+
engine.say(audio)
18+
engine.runAndWait()
19+
20+
21+
defwishMe():
22+
hour=int(datetime.datetime.now().hour)
23+
ifhour>=0andhour<12:
24+
speak("Good Morning!")
25+
26+
elifhour>=12andhour<18:
27+
speak("Good Afternoon!")
28+
29+
else:
30+
speak("Good Evening!")
31+
32+
speak("I am Lucifer Sir. Please tell me how may I help you")
33+
34+
deftakeCommand():
35+
#It takes microphone input from the user and returns string output
36+
37+
r=sr.Recognizer()
38+
withsr.Microphone()assource:
39+
print("Listening...")
40+
r.pause_threshold=1
41+
audio=r.listen(source)
42+
43+
try:
44+
print("Recognizing...")
45+
query=r.recognize_google(audio,language='en-in')
46+
print(f"User said:{query}\n")
47+
48+
exceptExceptionase:
49+
# print(e)
50+
print("Say that again please...")
51+
return"None"
52+
returnquery
53+
54+
defsendEmail(to,content):
55+
server=smtplib.SMTP('smtp.gmail.com',587)
56+
server.ehlo()
57+
server.starttls()
58+
server.login('youremail@gmail.com','your-password')
59+
server.sendmail('youremail@gmail.com',to,content)
60+
server.close()
61+
62+
if__name__=="__main__":
63+
wishMe()
64+
whileTrue:
65+
# if 1:
66+
query=takeCommand().lower()
67+
68+
# Logic for executing tasks based on query
69+
if'wikipedia'inquery:
70+
speak('Searching Wikipedia...')
71+
query=query.replace("wikipedia","")
72+
results=wikipedia.summary(query,sentences=2)
73+
speak("According to Wikipedia")
74+
print(results)
75+
speak(results)
76+
77+
elif'open youtube'inquery:
78+
webbrowser.open("youtube.com")
79+
80+
elif'open google'inquery:
81+
webbrowser.open("google.com")
82+
83+
elif'open stackoverflow'inquery:
84+
webbrowser.open("stackoverflow.com")
85+
86+
87+
elif'play music'inquery:
88+
music_dir='D:\\Non Critical\\songs\\Favorite Songs2'
89+
songs=os.listdir(music_dir)
90+
print(songs)
91+
os.startfile(os.path.join(music_dir,songs[0]))
92+
93+
elif'the time'inquery:
94+
strTime=datetime.datetime.now().strftime("%H:%M:%S")
95+
speak(f"Sir, the time is{strTime}")
96+
97+
elif'open code'inquery:
98+
codePath="C:\\Users\\GAURAV\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
99+
os.startfile(codePath)
100+
101+
elif'email to harry'inquery:
102+
try:
103+
speak("What should I say?")
104+
content=takeCommand()
105+
to="harryyourEmail@gmail.com"
106+
sendEmail(to,content)
107+
speak("Email has been sent!")
108+
exceptExceptionase:
109+
print(e)
110+
speak("Sorry my friend gaurav. I am not able to send this email")

‎CreditRisk.py‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#%%
2+
importwarnings
3+
warnings.filterwarnings('ignore')
4+
5+
importos
6+
importnumpyasnp
7+
importpandasaspd
8+
importscipy.statsasst
9+
importstatsmodels.apiassm
10+
importmatplotlib.pyplotasplt
11+
12+
fromsklearnimportlinear_model
13+
fromsklearn.metricsimportmean_squared_error,r2_score,confusion_matrix,accuracy_score
14+
fromsklearn.model_selectionimporttrain_test_split
15+
fromsklearn.metricsimportroc_curve
16+
fromsklearn.metricsimportroc_auc_score
17+
# %%
18+
os.chdir('D:/machine_learning/DATA_SET/credit_risk')
19+
df_a=pd.read_csv('credit_risk.csv')
20+
df_a.head()
21+
# %%
22+
df_a.isnull().sum()
23+
# %%
24+
df_a.dropna(axis=0,inplace=True)
25+
df_a.isnull().sum()
26+
# %%
27+
df_a.dtypes
28+
# %%
29+
df_a["CoapplicantIncome"]=df_a["CoapplicantIncome"].astype('float')
30+
df_a["ApplicantIncome"]=df_a["ApplicantIncome"].astype('float')
31+
print("AFTER CHANGING INT & OBJECT TO FLOAT")
32+
df_a.dtypes
33+
# %%
34+
df_a["Dependents"].value_counts()
35+
# %%
36+
cleanup_nums= {
37+
"Married": {"Yes":1,"No":0},
38+
"Self_Employed": {"Yes":1,"No":0},
39+
"Property_Area": {"Rural":0,"Urban":1,"Semiurban":2},
40+
"Education": {"Graduate":1,"Not Graduate":0},
41+
"Loan_Status": {"Y":1,"N":0},
42+
"Gender": {"Male":1,"Female":0},
43+
"Dependents": {"0":0,"1":1,"2":2,"3+":3},
44+
}
45+
46+
df_a.replace(cleanup_nums,inplace=True)
47+
df_a.head()
48+
# %%
49+
df_corr=df_a[['Gender','Married','Dependents','Education',
50+
'Self_Employed','ApplicantIncome','CoapplicantIncome','LoanAmount',
51+
'Loan_Amount_Term','Credit_History','Property_Area','Loan_Status']]
52+
53+
df_corr.head()
54+
# %%
55+
plt.imshow(df_corr.corr(),cmap=plt.cm.Blues ,interpolation='nearest')
56+
cmap='coolwarm'
57+
plt.colorbar()
58+
tick_marks= [iforiinrange(len(df_corr.columns))]
59+
plt.xticks(tick_marks,df_corr.columns,rotation='vertical')
60+
plt.yticks(tick_marks,df_corr.columns)
61+
plt.show()
62+
#%%
63+
boolean_col='Loan_Status'
64+
cols= ['Gender','Married','Dependents','Education','Self_Employed',
65+
'ApplicantIncome','CoapplicantIncome','Credit_History'
66+
]
67+
68+
xTrain=df_a[cols].values
69+
yTrain=df_a[boolean_col].values
70+
# %%
71+
st.chisqprob=lambdachisq,df:st.chi2.sf(chisq,df)
72+
73+
model=sm.Logit(yTrain,xTrain )
74+
result=model.fit()
75+
result.summary(xname=cols,yname=boolean_col,title='Logit Model',alpha=1)
76+
# %%
77+
defcalculate_accuracy(predictions,real):
78+
correct=0
79+
foriinrange(len(predictions)):
80+
ifround(predictions[i])==round(real[i]):
81+
correct+=1
82+
returncorrect*1.0/len(predictions)
83+
# %%
84+
train_predictions=result.predict(xTrain)
85+
86+
train_accuracy=calculate_accuracy(train_predictions,yTrain )
87+
print("Train Accuracy: ",train_accuracy*100 )
88+
# %%
89+
train_predictions= (train_predictions>0.5)
90+
91+
train_cm=confusion_matrix(yTrain,train_predictions,labels= [1.0,0.0])
92+
print(train_cm )
93+
# %%
94+
labels= ['0','1']
95+
cm=train_cm
96+
fig=plt.figure()
97+
ax=fig.add_subplot(111)
98+
cax=ax.matshow(cm,cmap='viridis')
99+
plt.title('Confusion matrix')
100+
fig.colorbar(cax)
101+
ax.set_xticklabels(['']+labels)
102+
ax.set_yticklabels(['']+labels)
103+
104+
r=0
105+
c=0
106+
forlistItemincm:
107+
forcellIteminlistItem:
108+
ax.text(c,r,cellItem,va='center',ha='center',color='r')
109+
c+=1
110+
c=0
111+
r+=1
112+
113+
plt.xlabel('Actual label')
114+
plt.ylabel('Predicted label')
115+
plt.show()
116+
# %%

‎Detect Capital‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Detect Capital
2+
Level-Easy
3+
4+
We define the usage of capitals in a word to be right when one of the following cases holds:
5+
All letters in this word are capitals, like "USA".
6+
All letters in this word are not capitals, like "leetcode".
7+
Only the first letter in this word is capital, like "Google".
8+
Given a string word, return true if the usage of capitals in it is right.
9+
Example 1:
10+
Input: word = "USA"
11+
Output: true
12+
Example 2:
13+
Input: word = "FlaG"
14+
Output: false
15+
Constraints:
16+
1 <= word.length <= 100
17+
word consists of lowercase and uppercase English letters.
18+
19+
Time Complexity-o(n)
20+
Space Complexity-o(1)
21+
22+
Java Solution
23+
24+
class Solution {
25+
public boolean detectCapitalUse(String word) {
26+
if(word.length()>=2 && word.charAt(0)>=97 && word.charAt(0)<=123 && word.charAt(1)>=65 && word.charAt(1)<=91)
27+
return false;
28+
for(int i=1;i<word.length()-1;i++){
29+
if(word.charAt(i)>=65 && word.charAt(i)<=91){
30+
if(word.charAt(i+1)>=65 && word.charAt(i+1)<=91);
31+
else
32+
return false;
33+
}
34+
else{
35+
if(word.charAt(i+1)>=97 && word.charAt(i+1)<=123);
36+
else
37+
return false;
38+
}
39+
}
40+
return true;
41+
}
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp