-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from KingFire25/br2
Br2
- Loading branch information
Showing
5 changed files
with
247 additions
and
0 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,35 @@ | ||
# Problem Title: Print Matrix in Spiral order | ||
|
||
## Problem Explanation | ||
|
||
Ex:- Given Matrix : | ||
1 2 3 | ||
4 5 6 | ||
7 8 9 | ||
Output- 1 2 3 6 9 8 7 4 5 | ||
|
||
## Logic and Intuition | ||
|
||
* An optimized approach will be to create 4 variables that store the upper ,lower ,left and right bound of the Matrix which decreases after each iteration. | ||
* We will iterate through every row and column in a spiral manner until the lower and right bound are greater than upper and left bound respectively. | ||
|
||
## Time Complexity and Space Complexity | ||
|
||
* Time Complexity: O(m*n) | ||
* Space Complexity: O(1) | ||
|
||
|
||
# Problem Title: Sieve of Eratosthenes | ||
|
||
To find all the prime numbers upto a given number. | ||
|
||
## Logic & Intuition | ||
|
||
* We will create a bool array which is used to check if a number is prime or not (initially all are set to true). | ||
* We will iterate the array $\sqrt{n}$ times and in each iteration we will mark all the multiples of i as false. | ||
* At the end of the loop the remaining array will contain only the prime numbers. | ||
|
||
## Time Complexity and Space Complexity | ||
|
||
* Time Complexity: O(n * log(log(n)) ) | ||
* Space Complexity: O(n) |
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,26 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
void SioErato(int n) // Sieve of Eratosthenes | ||
{ | ||
int i; | ||
bool t[n + 1]; | ||
fill(t, t + n + 1, true); | ||
t[0] = false, t[1] = false; | ||
for (i = 2; i * i <= n; i++) | ||
if(t[j]) | ||
for (int j = 2 * i; j <= n; j += i) | ||
if (j % i == 0) | ||
t[j] = false; | ||
|
||
for (i = 1; i <= n; i++) | ||
if (t[i] == true) | ||
cout << i << " "; | ||
} | ||
int main() | ||
{ | ||
int n; | ||
cout<<"Enter upper limit: "; | ||
// cin>>n; | ||
SioErato(1000); | ||
return 0; | ||
} |
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,40 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
void spiOrd(vector<vector<int>> &m) | ||
{ | ||
int i, l = 0, u = 0, d = m.size(), r = m[0].size(); | ||
while (l < r and u < d) | ||
{ | ||
for (i = l; i < r; i++) | ||
cout<<m[u][i]<<" "; | ||
u++; | ||
for (i = u; i < d; i++) | ||
cout<<m[i][r - 1]<<" "; | ||
r--; | ||
if (u < d) | ||
{ | ||
for (i = r - 1; i >= l; i--) | ||
cout<<m[d - 1][i]<<" "; | ||
d--; | ||
} | ||
if (l < r) | ||
{ | ||
for (i = d - 1; i >= u; i--) | ||
cout<<m[i][l]<<" "; | ||
l++; | ||
} | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n,r,c,i,j; | ||
cout<<"enter no. of rows and columns: "; | ||
cin>>r>>c; | ||
vector<vector<int>>v(r,vector<int>(c,0)); | ||
for(i=0;i<r;i++) | ||
for(j=0;j<c;j++) | ||
cin>>v[i][j]; | ||
spiOrd(v); | ||
return 0; | ||
} |
14 changes: 14 additions & 0 deletions
14
projects_Intermediate/PYTHON_DEVELOPMENT/GUI_Calculator_Ashutosh_Panda/README.md
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,14 @@ | ||
# Script Title | ||
|
||
A small python program that creates a calculator app | ||
|
||
## Requirements | ||
|
||
tkinter | ||
functools | ||
|
||
## How to run the script | ||
|
||
> py calculator.py | ||
## Screenshot/GIF showing the sample use of the script |
132 changes: 132 additions & 0 deletions
132
projects_Intermediate/PYTHON_DEVELOPMENT/GUI_Calculator_Ashutosh_Panda/calculator.py
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,132 @@ | ||
from tkinter import Tk, END, Entry, N, E, S, W, Button | ||
from tkinter import font | ||
from tkinter import Label | ||
from functools import partial | ||
|
||
|
||
def get_input(entry, argu): | ||
entry.insert(END, argu) | ||
|
||
|
||
def backspace(entry): | ||
input_len = len(entry.get()) | ||
entry.delete(input_len - 1) | ||
|
||
|
||
def clear(entry): | ||
entry.delete(0, END) | ||
|
||
|
||
def calc(entry): | ||
input_info = entry.get() | ||
try: | ||
output = str(eval(input_info.strip())) | ||
except ZeroDivisionError: | ||
popupmsg() | ||
output = "" | ||
clear(entry) | ||
entry.insert(END, output) | ||
|
||
|
||
def popupmsg(): | ||
popup = Tk() | ||
popup.resizable(0, 0) | ||
popup.geometry("120x100") | ||
popup.title("Alert") | ||
label = Label(popup, text="Cannot divide by 0 ! \n Enter valid values") | ||
label.pack(side="top", fill="x", pady=10) | ||
B1 = Button(popup, text="Okay", bg="#DDDDDD", command=popup.destroy) | ||
B1.pack() | ||
|
||
|
||
def cal(): | ||
root = Tk() | ||
root.title("Calc") | ||
root.resizable(0, 0) | ||
|
||
entry_font = font.Font(size=15) | ||
entry = Entry(root, justify="right", font=entry_font) | ||
entry.grid(row=0, column=0, columnspan=4, | ||
sticky=N + W + S + E, padx=5, pady=5) | ||
|
||
cal_button_bg = '#FF6600' | ||
num_button_bg = '#4B4B4B' | ||
other_button_bg = '#DDDDDD' | ||
text_fg = '#FFFFFF' | ||
button_active_bg = '#C0C0C0' | ||
|
||
num_button = partial(Button, root, fg=text_fg, bg=num_button_bg, | ||
padx=10, pady=3, activebackground=button_active_bg) | ||
cal_button = partial(Button, root, fg=text_fg, bg=cal_button_bg, | ||
padx=10, pady=3, activebackground=button_active_bg) | ||
|
||
button7 = num_button(text='7', bg=num_button_bg, | ||
command=lambda: get_input(entry, '7')) | ||
button7.grid(row=2, column=0, pady=5) | ||
|
||
button8 = num_button(text='8', command=lambda: get_input(entry, '8')) | ||
button8.grid(row=2, column=1, pady=5) | ||
|
||
button9 = num_button(text='9', command=lambda: get_input(entry, '9')) | ||
button9.grid(row=2, column=2, pady=5) | ||
|
||
button10 = cal_button(text='+', command=lambda: get_input(entry, '+')) | ||
button10.grid(row=4, column=3, pady=5) | ||
|
||
button4 = num_button(text='4', command=lambda: get_input(entry, '4')) | ||
button4.grid(row=3, column=0, pady=5) | ||
|
||
button5 = num_button(text='5', command=lambda: get_input(entry, '5')) | ||
button5.grid(row=3, column=1, pady=5) | ||
|
||
button6 = num_button(text='6', command=lambda: get_input(entry, '6')) | ||
button6.grid(row=3, column=2, pady=5) | ||
|
||
button11 = cal_button(text='-', command=lambda: get_input(entry, '-')) | ||
button11.grid(row=3, column=3, pady=5) | ||
|
||
button1 = num_button(text='1', command=lambda: get_input(entry, '1')) | ||
button1.grid(row=4, column=0, pady=5) | ||
|
||
button2 = num_button(text='2', command=lambda: get_input(entry, '2')) | ||
button2.grid(row=4, column=1, pady=5) | ||
|
||
button3 = num_button(text='3', command=lambda: get_input(entry, '3')) | ||
button3.grid(row=4, column=2, pady=5) | ||
|
||
button12 = cal_button(text='*', command=lambda: get_input(entry, '*')) | ||
button12.grid(row=2, column=3, pady=5) | ||
|
||
button0 = num_button(text='0', command=lambda: get_input(entry, '0')) | ||
#button0.grid(row=5, column=0, columnspan=2, padx=3, pady=5, sticky=N + S + E + W) | ||
button0.grid(row=5, column=0, pady=5) | ||
|
||
button13 = num_button(text='.', command=lambda: get_input(entry, '.')) | ||
button13.grid(row=5, column=1, pady=5) | ||
|
||
button14 = Button(root, text='/', fg=text_fg, bg=cal_button_bg, padx=10, pady=3, | ||
command=lambda: get_input(entry, '/')) | ||
button14.grid(row=1, column=3, pady=5) | ||
|
||
button15 = Button(root, text='<-', bg=other_button_bg, padx=10, pady=3, | ||
command=lambda: backspace(entry), activebackground=button_active_bg) | ||
button15.grid(row=1, column=0, columnspan=2, | ||
padx=3, pady=5, sticky=N + S + E + W) | ||
|
||
button16 = Button(root, text='C', bg=other_button_bg, padx=10, pady=3, | ||
command=lambda: clear(entry), activebackground=button_active_bg) | ||
button16.grid(row=1, column=2, pady=5) | ||
|
||
button17 = Button(root, text='=', fg=text_fg, bg=cal_button_bg, padx=10, pady=3, | ||
command=lambda: calc(entry), activebackground=button_active_bg) | ||
button17.grid(row=5, column=3, pady=5) | ||
|
||
button18 = Button(root, text='^', fg=text_fg, bg=cal_button_bg, padx=10, pady=3, | ||
command=lambda: get_input(entry, '**')) | ||
button18.grid(row=5, column=2, pady=5) | ||
|
||
root.mainloop() | ||
|
||
|
||
if __name__ == '__main__': | ||
cal() |