Skip to content

bhoomi.639 #644

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions Day3/DSA1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] array = new int[scan.nextInt()];
for(int i = 0; i < array.length; i++){
array[i] = scan.nextInt();
}
scan.close();

for(int i = array.length - 1; i >= 0; i--){
System.out.print(array[i] + " ");
}
}
}
68 changes: 68 additions & 0 deletions Day3/DSA2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cassert>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <iostream>

#define pb push_back
#define all(x) (x).begin(), (x).end()

#ifdef KAZAR
#define eprintf(...) fprintf(stderr,VA_ARGS)
#else
#define eprintf(...) 0
#endif

using namespace std;

template<class T> inline void umax(T &a,T b){if(a < b) a = b;}
template<class T> inline void umin(T &a,T b){if(a > b) a = b;}
template<class T> inline T abs(T a){return a > 0 ? a : -a;}

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int inf = 1e9 + 143;
const ll longinf = 1e18 + 143;

inline int read(){int x;scanf(" %d",&x);return x;}

int main(){

#ifdef KAZAR
freopen("f.input","r",stdin);
freopen("f.output","w",stdout);
freopen("error","w",stderr);
#endif

int n = read();
int q = read();
assert(1 <= n && n <= 1e5);
assert(1 <= q && q <= 1e5);
int lastans = 0;
vector<vi> seq(n);
for (int i = 0; i < q; i++) {
int t = read();
int x = read();
int y = read();
int real_x = (x ^ lastans) % n;
if (t == 1) {
seq[real_x].pb(y);
} else {
assert(seq[real_x].size());
lastans = seq[real_x][y % seq[real_x].size()];
printf("%d\n", lastans);
}
}

return 0;
}
49 changes: 49 additions & 0 deletions Day3/DSA3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.*;

public class Solution {

public static int[] rotateArray(int[] arr, int d){
// Because the constraints state d < n, we need not concern ourselves with shifting > n units.
int n = arr.length;

// Create a temporary d-element array to store elements shifted to the left of index 0:
int[] temp_arr = Arrays.copyOfRange(arr, 0, d);

// Shift elements from indices d through n to indices 0 through d - 1:
for(int i = d; i < n; i++) {
arr[i - d] = arr[i];
}

// Copy the d shifted elements from the temporary array back to the original array:
for(int i = n - d; i < n; i++) {
arr[i] = temp_arr[i-n+d];
}

return arr;
}

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int d = scanner.nextInt();
int[] numbers = new int[n];

// Fill initial array:
for(int i = 0; i < n; i++){
numbers[i] = scanner.nextInt();
}

// Rotate array by d elements:
numbers = rotateArray(numbers, d);

// Print array's elements as a single line of space-separated values:
for(int i : numbers) {
System.out.print(i + " ");
}
System.out.println();

scanner.close();
}

}
26 changes: 26 additions & 0 deletions Day3/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//inst classes//

const ft = new Fetch();
const ui = new UI();

//add event listeners//

const search = document.getElementById("searchUser");
const button = document.getElementById("submit");
button.addEventListener("click", () => {
const currentVal = search.value;

ft.getCurrent(currentVal).then((data) => {
//call a UI method//
ui.populateUI(data);
//call saveToLS
ui.saveToLS(data);
});
});

//event listener for local storage

window.addEventListener("DOMContentLoaded", () => {
const dataSaved = ui.getFromLS();
ui.populateUI(dataSaved);
});
49 changes: 49 additions & 0 deletions Day3/class UI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class UI {
constructor() {
this.uiContainer = document.getElementById("content");
this.city;
this.defaultCity = "London";
}

populateUI(data) {
//de-structure vars

//add them to inner HTML

this.uiContainer.innerHTML = `

<div class="card mx-auto mt-5" style="width: 18rem;">
<div class="card-body justify-content-center">
<h5 class="card-title">${data.name}</h5>
<h6 class="card-subtitle mb-2 text-muted">Highs of ${parseInt(data.main.temp_max-273)}. Lows of ${parseInt(data.main.temp_min-275)}</h6>
<p class="card-text ">Weather conditions are described as: ${data.weather[0].description}</p>

</div>
</div>


`;
}

clearUI() {
uiContainer.innerHTML = "";
}

saveToLS(data) {
localStorage.setItem("city", JSON.stringify(data));
}

getFromLS() {
if (localStorage.getItem("city" == null)) {
return this.defaultCity;
} else {
this.city = JSON.parse(localStorage.getItem("city"));
}

return this.city;
}

clearLS() {
localStorage.clear();
}
}
17 changes: 17 additions & 0 deletions Day3/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Fetch {
async getCurrent(input) {
const myKey = "39a9a737b07b4b703e3d1cd1e231eedc";

//make request to url

const response = await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${input}&appid=${myKey}`
);

const data = await response.json();

console.log(data);

return data;
}
}
154 changes: 154 additions & 0 deletions Day3/tictactoe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
using namespace std;

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};

int checkwin();
void board();

int main()
{
int player = 1,i,choice;

char mark;
do
{
board();
player=(player%2)?1:2;

cout << "Player " << player << ", enter a number: ";
cin >> choice;

mark=(player == 1) ? 'X' : 'O';

if (choice == 1 && square[1] == '1')

square[1] = mark;
else if (choice == 2 && square[2] == '2')

square[2] = mark;
else if (choice == 3 && square[3] == '3')

square[3] = mark;
else if (choice == 4 && square[4] == '4')

square[4] = mark;
else if (choice == 5 && square[5] == '5')

square[5] = mark;
else if (choice == 6 && square[6] == '6')

square[6] = mark;
else if (choice == 7 && square[7] == '7')

square[7] = mark;
else if (choice == 8 && square[8] == '8')

square[8] = mark;
else if (choice == 9 && square[9] == '9')

square[9] = mark;
else
{
cout<<"Invalid move ";

player--;
cin.ignore();
cin.get();
}
i=checkwin();

player++;
}while(i==-1);
board();
if(i==1)

cout<<"==>\aPlayer "<<--player<<" win ";
else
cout<<"==>\aGame draw";

cin.ignore();
cin.get();
return 0;
}

/***************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
****************/

int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])

return 1;
else if (square[4] == square[5] && square[5] == square[6])

return 1;
else if (square[7] == square[8] && square[8] == square[9])

return 1;
else if (square[1] == square[4] && square[4] == square[7])

return 1;
else if (square[2] == square[5] && square[5] == square[8])

return 1;
else if (square[3] == square[6] && square[6] == square[9])

return 1;
else if (square[1] == square[5] && square[5] == square[9])

return 1;
else if (square[3] == square[5] && square[5] == square[7])

return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')

return 0;
else
return -1;
}


/***********************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
************************/


void board()
{
system("cls");
cout << "\n\n\tTic Tac Toe\n\n";

cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;

cout << " | | " << endl;
cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl;

cout << "__|_|__" << endl;
cout << " | | " << endl;

cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl;

cout << "__|_|__" << endl;
cout << " | | " << endl;

cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl;

cout << " | | " << endl << endl;
}

Loading