xxxxxxxxxx
# Execution of the Python Script
# - Save the python script with <Python_Script_Name>.py
# - Run the below command by giving the x1 y1 r1 ... values
# - The values are assumed to be Real/Integer constants
# python <Python_Script_Name>.py x1 y1 r1 x2 y2 r2 x3 y3 r3
#
# If the command is not executed as provided above, the script
# would exit leaving "Check the input attributes" message.
import sys # Python Default sys module
if len(sys.argv) == 10:
# Tower1 Inputs are casted to float values
x1 = float(sys.argv[1])
y1 = float(sys.argv[2])
r1 = float(sys.argv[3])
# Tower2 Inputs are casted to float values
x2 = float(sys.argv[4])
y2 = float(sys.argv[5])
r2 = float(sys.argv[6])
# Tower3 Inputs are casted to float values
x3 = float(sys.argv[7])
y3 = float(sys.argv[8])
r3 = float(sys.argv[9])
else:
print('Check the input attributes')
exit(2)
# Printing the entered input values
print('Input attributes for the three towers are : ')
print('Tower 1 attributes x1, y1, r1 : '),
print(x1, y1, r1)
print('Tower 2 attributes x2, y2, r2 : '),
print(x2, y2, r2)
print('Tower 3 attributes x3, y3, r3 : '),
print(x3, y3, r3)
# Calculating parameters based on the input values
A = (2 * x2) - (2 * x1)
B = (2 * y2) - (2 * y1)
C = r1 * 2 - r2 * 2 - x1 * 2 + x2 * 2 - y1 * 2 + y2 * 2
D = (2 * x3) - (2 * x2)
E = (2 * y3) - (2 * y2)
F = r2 * 2 - r3 * 2 - x2 * 2 + x3 * 2 - y2 * 2 + y3 * 2
# Calculate the device coordinates
Xcoordinate = ((C * E) - (F * B))/((E * A) - (B * D))
Ycoordinate = ((C * D) - (A * F))/((B * D) - (A * E))
# Printing the output values
print('Cell Phone Device X, Y coordinates are : '),
print(Xcoordinate, Ycoordinate)
# End of the file (EoF)
xxxxxxxxxx
def create(n):
l = []
for i in range(1, n+1):
l.append(i)
return l
def operation(n ,p):
l = []
kl = []
if p < n-1:
return kl
t = 0
c = 1
for i in range(n-1, 0, -1):
c += 1
if t+c+i-1 >= p:
r = p-t-i+1
l.append(r)
for k in range(i-1):
l.append(1)
t = p
break
t += c
l.append(c)
if t < p:
return k1
return l
def operate(l ,ope):
length = len(ope)
for i in range(elngth):
t = len(l) - (i+2)
sp = t + ope[i]
l = l[:t] + list(reversed(l[t:sp])) + l[sp:]
return l
def main():
inp = input().split()
n = int(inp[0])
p = int(inp[1])
l = create(n)
ope = operation(n, p)
l = operate(l, ope)
result = " "
if ope:
for item in l:
result += str(item) + " "
else
result = "IMPOSSIBLE"
print(f'Case # {str(i+1)} : {str(result)}')
for i in range(int(input())):
main()
xxxxxxxxxx
// Program to print path from root node to destination node
// for N*N -1 puzzle algorithm using Branch and Bound
// The solution assumes that instance of puzzle is solvable
#include <bits/stdc++.h>
using namespace std;
#define N 3
// state space tree nodes
struct Node
{
// stores the parent node of the current node
// helps in tracing path when the answer is found
Node* parent;
// stores matrix
int mat[N][N];
// stores blank tile coordinates
int x, y;
// stores the number of misplaced tiles
int cost;
// stores the number of moves so far
int level;
};
// Function to print N x N matrix
int printMatrix(int mat[N][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
printf("%d ", mat[i][j]);
printf("\n");
}
}
// Function to allocate a new node
Node* newNode(int mat[N][N], int x, int y, int newX,
int newY, int level, Node* parent)
{
Node* node = new Node;
// set pointer for path to root
node->parent = parent;
// copy data from parent node to current node
memcpy(node->mat, mat, sizeof node->mat);
// move tile by 1 position
swap(node->mat[x][y], node->mat[newX][newY]);
// set number of misplaced tiles
node->cost = INT_MAX;
// set number of moves so far
node->level = level;
// update new blank tile cordinates
node->x = newX;
node->y = newY;
return node;
}
// bottom, left, top, right
int row[] = { 1, 0, -1, 0 };
int col[] = { 0, -1, 0, 1 };
// Function to calculate the number of misplaced tiles
// ie. number of non-blank tiles not in their goal position
int calculateCost(int initial[N][N], int final[N][N])
{
int count = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (initial[i][j] && initial[i][j] != final[i][j])
count++;
return count;
}
// Function to check if (x, y) is a valid matrix cordinate
int isSafe(int x, int y)
{
return (x >= 0 && x < N && y >= 0 && y < N);
}
// print path from root node to destination node
void printPath(Node* root)
{
if (root == NULL)
return;
printPath(root->parent);
printMatrix(root->mat);
printf("\n");
}
// Comparison object to be used to order the heap
struct comp
{
bool operator()(const Node* lhs, const Node* rhs) const
{
return (lhs->cost + lhs->level) > (rhs->cost + rhs->level);
}
};
// Function to solve N*N - 1 puzzle algorithm using
// Branch and Bound. x and y are blank tile coordinates
// in initial state
void solve(int initial[N][N], int x, int y,
int final[N][N])
{
// Create a priority queue to store live nodes of
// search tree;
priority_queue<Node*, std::vector<Node*>, comp> pq;
// create a root node and calculate its cost
Node* root = newNode(initial, x, y, x, y, 0, NULL);
root->cost = calculateCost(initial, final);
// Add root to list of live nodes;
pq.push(root);
// Finds a live node with least cost,
// add its childrens to list of live nodes and
// finally deletes it from the list.
while (!pq.empty())
{
// Find a live node with least estimated cost
Node* min = pq.top();
// The found node is deleted from the list of
// live nodes
pq.pop();
// if min is an answer node
if (min->cost == 0)
{
// print the path from root to destination;
printPath(min);
return;
}
// do for each child of min
// max 4 children for a node
for (int i = 0; i < 4; i++)
{
if (isSafe(min->x + row[i], min->y + col[i]))
{
// create a child node and calculate
// its cost
Node* child = newNode(min->mat, min->x,
min->y, min->x + row[i],
min->y + col[i],
min->level + 1, min);
child->cost = calculateCost(child->mat, final);
// Add child to list of live nodes
pq.push(child);
}
}
}
}
// Driver code
int main()
{
// Initial configuration
// Value 0 is used for empty space
int initial[N][N] =
{
{1, 2, 3},
{5, 6, 0},
{7, 8, 4}
};
// Solvable Final configuration
// Value 0 is used for empty space
int final[N][N] =
{
{1, 2, 3},
{5, 8, 6},
{0, 7, 4}
};
// Blank tile coordinates in initial
// configuration
int x = 1, y = 2;
solve(initial, x, y, final);
return 0;
}
xxxxxxxxxx
import torch
import torch.nn as nn
import torch.nn.functional as F
class BidirectionalLSTM(nn.Module):
def __init__(self, n_in, n_hidden, n_out):
super(BidirectionalLSTM, self).__init__()
self.rnn = nn.LSTM(n_in, n_hidden, bidirectional=True)
self.embedding = nn.Linear(n_hidden * 2, n_out)
def forward(self, input):
recurrent, _ = self.rnn(input)
T, b, h = recurrent.size()
t_rec = recurrent.view(T * b, h)
output = self.embedding(t_rec) # [T * b, nOut]
output = output.view(T, b, -1)
return output
xxxxxxxxxx
#include<iostream>
#include<math.h>
#define vL 0.4
using namespace std;
struct generator
{
float IL,theat,Pout;
};
typedef struct generator GENERATOR;
int main()
{
int i=0,n;
float sum=0,avg,low,high,il,theat;
cout<<"Enter the value for 'n' : ";
cin>>n;
GENERATOR g[n];
while(i<n)
{
cout<<"Enter Voltage and Current";
cin>>il>>theat;
if(il>0&&theat>=35&&theat<=45){
g[i].IL=il;
g[i].theat=theat;
g[i].Pout=sqrt(3)*il*cos(theat);
cout<<g[i].Pout;
if(i==0)
{
low=g[i].Pout;
high=g[i].Pout;
}
++i;
}else
cout<<"\nEnter Valid data(il>0 and theat>=-35 and theat<=45)";
}
i=1;
while(i<n)
{
if(low>g[i].Pout)
low=g[i].Pout;
if(high<g[i].Pout)
high=g[i].Pout;
sum+=g[i].Pout;
i++;
}
avg=sum/n;
cout<<"\nThe Lowest Output Power :"<<low;
cout<<"\nThe highest Output Power :"<<high;
cout<<"\nThe Average Output Power :"<<avg;
}
OUTPUT
xxxxxxxxxx
void decrypt(string &text, string &key){
for(size_t i=0;i<text.length()-1;i++){
for (int j=0;j<26;j++){
if (text[i]==key[j]){
text[i]=j+97;
break;
}
}
}
}
xxxxxxxxxx
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void obradi(const vector<int>& particija, int k) {
for (int i = 0; i < k; i++)
cout << particija[i] << " ";
cout << endl;
}
void obradiParticije(int n, int smax, vector<int>& particija, int k) {
if (n <= 0)
obradi(particija, k);
else {
for (int s = 1; s <= min(n, smax); s++) {
particija[k] = s;
obradiParticije(n-s, s, particija, k+1);
}
}
void obradiParticije(int n) {
vector<int> particija(n);
obradiParticije(n, n, particija, 0);
}
int main() {
int n;
cin >> n;
obradiParticije(n);
xxxxxxxxxx
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
struct n{
int d;
struct n*next;
};
void push(struct n**headref, int new_d)
{
struct n* new_node=new n;
new_node->d=new_d;
new_node->next=(*headref);
(*headref)=new_node;
}
float avgofnodes(struct n*head)
{
if(!head){return -1;}
int c=0;
int s=0;
float avg =0.0;
struct n*now=head;
while(now!=NULL)
{
c++;
s+=now->d;
now=now->next;
}
avg=(double)s/c;
return avg;
}
int main()
{
struct n*head=NULL;
push(&head , 7);
push(&head, 6);
push(&head, 8);
push(&head, 4);
push(&head, 1);
cout<<"Average of nodes = "<<avgofnodes(head);
return 0;
}
xxxxxxxxxx
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
struct n{
int d;
struct n*next;
};
void push(struct n**headref, int new_d)
{
struct n* new_node=new n;
new_node->d=new_d;
new_node->next=(*headref);
(*headref)=new_node;
}
float avgofnodes(struct n*head)
{
if(!head){return -1;}
int c=0;
int s=0;
float avg =0.0;
struct n*now=head;
while(now!=NULL)
{
c++;
s+=now->d;
now=now->next;
}
avg=(double)s/c;
return avg;
}
int main()
{
struct n*head=NULL;
push(&head , 7);
push(&head, 6);
push(&head, 8);
push(&head, 4);
push(&head, 1);
cout<<"Average of nodes = "<<avgofnodes(head);
return 0;
}