-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MukulCode:master' into my-new-branch
- Loading branch information
Showing
52 changed files
with
2,146 additions
and
35 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Code in cpp to tell if there exists a pair in array whose | ||
// sum results in x. | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Function to print pairs | ||
void printPairs(int a[], int n, int x) | ||
{ | ||
int i; | ||
int rem[x]; | ||
// initializing the rem values with 0's. | ||
for (i = 0; i < x; i++) | ||
rem[i] = 0; | ||
// Perform the remainder operation only if the element | ||
// is x, as numbers greater than x can't be used to get | ||
// a sum x. Updating the count of remainders. | ||
for (i = 0; i < n; i++) | ||
if (a[i] < x) | ||
rem[a[i] % x]++; | ||
|
||
// Traversing the remainder list from start to middle to | ||
// find pairs | ||
for (i = 1; i < x / 2; i++) { | ||
if (rem[i] > 0 && rem[x - i] > 0) { | ||
// The elements with remainders i and x-i will | ||
// result to a sum of x. Once we get two | ||
// elements which add up to x , we print x and | ||
// break. | ||
cout << "Yes\n"; | ||
break; | ||
} | ||
} | ||
|
||
// Once we reach middle of remainder array, we have to | ||
// do operations based on x. | ||
if (i >= x / 2) { | ||
if (x % 2 == 0) { | ||
// if x is even and we have more than 1 elements | ||
// with remainder x/2, then we will have two | ||
// distinct elements which add up to x. if we | ||
// dont have more than 1 element, print "No". | ||
if (rem[x / 2] > 1) | ||
cout << "Yes\n"; | ||
else | ||
cout << "No\n"; | ||
} | ||
else { | ||
// When x is odd we continue the same process | ||
// which we did in previous loop. | ||
if (rem[x / 2] > 0 && rem[x - x / 2] > 0) | ||
cout << "Yes\n"; | ||
else | ||
cout << "No\n"; | ||
} | ||
} | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
int A[] = { 1, 4, 45, 6, 10, 8 }; | ||
int n = 16; | ||
int arr_size = sizeof(A) / sizeof(A[0]); | ||
|
||
// Function calling | ||
printPairs(A, arr_size, n); | ||
|
||
return 0; | ||
} | ||
//Time Complexity== O(N+X); | ||
//Auxiliary Space: O(X) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import './covid.css' | ||
const Covid = () => { | ||
const [data, setData] = useState([]); | ||
const getCovidData = async () => { | ||
try { | ||
const res = await fetch('https://data.covid19india.org/data.json'); | ||
const actualData = await res.json(); | ||
console.log(actualData.statewise[0]); | ||
setData(actualData.statewise[0]); | ||
} catch(err){ | ||
console.log(err); | ||
} | ||
} | ||
|
||
useEffect(() =>{ | ||
getCovidData(); | ||
}, []); | ||
return ( | ||
<> | ||
<section> | ||
<h1>🔴 LIVE COVID-19 </h1> | ||
<h2> COVID-19 TRACKER DETAIL </h2> | ||
<ul> | ||
<li className="card 1"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>OUR </span>COUNTRY</p> | ||
<p className="card__total card__small"></p>INDIA</div> | ||
</div> | ||
</li> | ||
<li className="card 2"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>TOTAL </span>RECOVERED</p> | ||
<p className="card__total card__small"></p>{data.recovered}</div> | ||
</div> | ||
</li><li className="card 3"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>TOATL </span>CONFIRMED</p> | ||
<p className="card__total card__small"></p>{data.confirmed}</div> | ||
</div> | ||
</li><li className="card 4"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>TOATL </span>DEATHS</p> | ||
<p className="card__total card__small"></p>{data.deaths}</div> | ||
</div> | ||
</li><li className="card 5"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>TOATL </span>ACTIVE</p> | ||
<p className="card__total card__small"></p>{data.active}</div> | ||
</div> | ||
</li><li className="card 6"> | ||
<div className="card__main"> | ||
<div className="card__inner"> | ||
<p className="card__name"><span>LAST </span>UPDATED</p> | ||
<p className="card__total card__small"></p>{data.lastupdatedtime}</div> | ||
</div> | ||
</li> | ||
</ul> | ||
</section> | ||
</> | ||
) | ||
} | ||
export default Covid |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import tkinter as tk | ||
from tkinter import * | ||
import tkinter.messagebox | ||
|
||
root = tk.Tk() | ||
|
||
root.title("Currency Conversion") | ||
|
||
Tops = Frame(root, bg='#e6e5e5', pady=2, width=1850, height=100, relief="ridge") | ||
Tops.grid(row=0, column=0) | ||
|
||
headlabel = tk.Label(Tops, font=('lato black', 19, 'bold'), text=' Currency Converter ', | ||
bg='#e6e5e5', fg='black') | ||
headlabel.grid(row=1, column=0, sticky=W) | ||
|
||
variable1 = tk.StringVar(root) | ||
variable2 = tk.StringVar(root) | ||
|
||
variable1.set("currency") | ||
variable2.set("currency") | ||
|
||
|
||
def RealTimeCurrencyConversion(): | ||
from forex_python.converter import CurrencyRates | ||
c = CurrencyRates() | ||
|
||
from_currency = variable1.get() | ||
to_currency = variable2.get() | ||
|
||
if (Amount1_field.get() == ""): | ||
tkinter.messagebox.showinfo("Error !!", "Amount Not Entered.\n Please a valid amount.") | ||
|
||
elif (from_currency == "currency" or to_currency == "currency"): | ||
tkinter.messagebox.showinfo("Error !!", | ||
"Currency Not Selected.\n Please select FROM and TO Currency form menu.") | ||
|
||
else: | ||
new_amt = c.convert(from_currency, to_currency, float(Amount1_field.get())) | ||
new_amount = float("{:.4f}".format(new_amt)) | ||
Amount2_field.insert(0, str(new_amount)) | ||
|
||
|
||
def clear_all(): | ||
Amount1_field.delete(0, tk.END) | ||
Amount2_field.delete(0, tk.END) | ||
|
||
|
||
CurrenyCode_list = ["INR", "USD", "CAD", "CNY", "DKK", "EUR"] | ||
|
||
root.configure(background='#e6e5e5') | ||
root.geometry("700x400") | ||
|
||
Label_1 = Label(root, font=('lato black', 27, 'bold'), text="", padx=2, pady=2, bg="#e6e5e5", fg="black") | ||
Label_1.grid(row=1, column=0, sticky=W) | ||
|
||
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t Amount : ", bg="#e6e5e5", fg="black") | ||
label1.grid(row=2, column=0, sticky=W) | ||
|
||
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t From Currency : ", bg="#e6e5e5", fg="black") | ||
label1.grid(row=3, column=0, sticky=W) | ||
|
||
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t To Currency : ", bg="#e6e5e5", fg="black") | ||
label1.grid(row=4, column=0, sticky=W) | ||
|
||
label1 = tk.Label(root, font=('lato black', 15, 'bold'), text="\t Converted Amount : ", bg="#e6e5e5", fg="black") | ||
label1.grid(row=8, column=0, sticky=W) | ||
|
||
Label_1 = Label(root, font=('lato black', 7, 'bold'), text="", padx=2, pady=2, bg="#e6e5e5", fg="black") | ||
Label_1.grid(row=5, column=0, sticky=W) | ||
|
||
Label_1 = Label(root, font=('lato black', 7, 'bold'), text="", padx=2, pady=2, bg="#e6e5e5", fg="black") | ||
Label_1.grid(row=7, column=0, sticky=W) | ||
|
||
FromCurrency_option = tk.OptionMenu(root, variable1, *CurrenyCode_list) | ||
ToCurrency_option = tk.OptionMenu(root, variable2, *CurrenyCode_list) | ||
|
||
FromCurrency_option.grid(row=3, column=0, ipadx=45, sticky=E) | ||
ToCurrency_option.grid(row=4, column=0, ipadx=45, sticky=E) | ||
|
||
Amount1_field = tk.Entry(root) | ||
Amount1_field.grid(row=2, column=0, ipadx=28, sticky=E) | ||
|
||
Amount2_field = tk.Entry(root) | ||
Amount2_field.grid(row=8, column=0, ipadx=31, sticky=E) | ||
|
||
Label_9 = Button(root, font=('arial', 15, 'bold'), text=" Convert ", padx=2, pady=2, bg="lightblue", fg="white", | ||
command=RealTimeCurrencyConversion) | ||
Label_9.grid(row=6, column=0) | ||
|
||
Label_1 = Label(root, font=('lato black', 7, 'bold'), text="", padx=2, pady=2, bg="#e6e5e5", fg="black") | ||
Label_1.grid(row=9, column=0, sticky=W) | ||
|
||
Label_9 = Button(root, font=('arial', 15, 'bold'), text=" Clear All ", padx=2, pady=2, bg="lightblue", fg="white", | ||
command=clear_all) | ||
Label_9.grid(row=10, column=0) | ||
|
||
root.mainloop() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Diff Utility | ||
|
||
A diff utility takes in two files and command-line arguments and compares them for changes. The changes are then shown as output indication what has changed where. | ||
|
||
## How to get started? | ||
|
||
Any version of Python 3 is good enough to run this program. Additionally the ``rich`` package is required. Install it via the terminal. | ||
|
||
``` | ||
pip install rich | ||
``` | ||
|
||
Or | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Run the program | ||
|
||
Run the program from the terminal as follows: | ||
|
||
``` | ||
python diff.py <file1.txt> <file2.txt> | ||
``` | ||
|
||
Or on Linux do: | ||
|
||
``` | ||
./diff.py <file1.txt> <file2.txt> | ||
``` | ||
|
||
Screenshot: | ||
|
||
![pydiff](pydiff.jpg) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# sys: for reading command-line arguments. | ||
# rich: for coloring the text. | ||
import sys | ||
from rich import print | ||
|
||
# Print Usage message if enough arguments are not passed. | ||
if len(sys.argv) < 3: | ||
print("Usage:") | ||
print("\tMust provide two file names as command-line arguments.") | ||
print("\tdiff.py <orignal_file> <changed_file>") | ||
exit(1) | ||
|
||
orignal = sys.argv[1] | ||
changed = sys.argv[2] | ||
|
||
cr = "bold red" | ||
cg = "bold green" | ||
|
||
# Read the contents of the files in lists. | ||
orignal_contents = open(orignal, "r").readlines() | ||
changed_contents = open(changed, "r").readlines() | ||
|
||
co = "green" | ||
sy = f"[bold {co}][+]" | ||
|
||
print() | ||
|
||
# Determine which file has changed much. | ||
if len(changed_contents) <= len(orignal_contents): | ||
co = "red" | ||
sy = f"[bold {co}][-]" | ||
smallest_sloc, largest_sloc = changed_contents, orignal_contents | ||
else: | ||
smallest_sloc, largest_sloc = orignal_contents, changed_contents | ||
|
||
# Go over all the lines to check the changes. | ||
for line in range(0, len(smallest_sloc)): | ||
if orignal_contents[line] == changed_contents[line]: | ||
# Ignore if the lines are same. | ||
continue | ||
else: | ||
# Display the changes on the respective lines of the files. | ||
oc = orignal_contents[line] | ||
cc = changed_contents[line] | ||
print(f"[{cr}][-] Line {line + 1}:[{cr}] {oc}", end="") | ||
print(f"[{cg}][+] Line {line + 1}:[{cg}] {cc}") | ||
|
||
# Show the additions or deletions for the file that is the largest. | ||
if line == len(smallest_sloc) - 1: | ||
for new_line in range(line + 1, len(largest_sloc)): | ||
ls = largest_sloc[new_line] | ||
print(f"{sy} Line {new_line + 1}:[bold {co}] {ls}") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Factorial for an Integer | ||
|
||
const number = parseInt(prompt('Enter a Integer : ')); | ||
//condition | ||
|
||
if(number < 0){ | ||
console.log('Error! Factorial for negative number does not exist.'); | ||
} | ||
|
||
else if(number == 0) { | ||
console.log(`The factorial of ${number} is 1.`); | ||
} | ||
|
||
else { let factorial = 1; | ||
for(i=1; i<= number; i++) | ||
{ | ||
factorial *= i; | ||
} | ||
console.log(`The factorial of ${number} is ${fact}.`); | ||
} |
Oops, something went wrong.