Found 26504 Articles for Server Side Programming

html5lib and lxml parsers in Python

Pradeep Elance
Updated on 20-Dec-2019 11:19:19

743 Views

html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers. It can parse almost all the elements of an HTML doc, breaking it down into different tags and pieces which can be filtered out for various use cases. It parses the text the same way as done by the major browsers. It can also tackle broken HTML tags and add some necessary tags to complete the structure. Also it is written in pure python code.lxml is also a similar parser but driven by XML ... Read More

C Program for focal length of a lens

Sunidhi Bansal
Updated on 20-Dec-2019 11:20:43

413 Views

Given two floating values; image distance and object distance from a lens; the task is to print the focal length of the lens.What is focal length?Focal length of an optical system is the distance between the center of lens or curved mirror and its focus.Let’s understand with the help of figure given below −In the above figure i is the object, and F is the image of the object which is formed and f is the focal length of the image.So to find the focal length of the image from the lens the formula is −1F= 1O+1IWhere, F is the ... Read More

How to assign values to variables in Python

Pradeep Elance
Updated on 20-Dec-2019 11:07:16

4K+ Views

Variable assignment is a very basic requirement in any computer programming language. In python there are multiple ways we can declare a variable and assign value to it. Below we see each of them.Direct InitialisationIn this method, we directly declare the variable and assign a value using the = sign. If the variable is declare multiple times, then the last declaration’s value will be used by the program.Examplex = 5 x = 9 print(a)Running the above code gives us the following result:Output9Using if-elseWe can initialize value of a variable using some conditions. The evaluation of the result of the condition ... Read More

Program for Mobius Function in C++

Sunidhi Bansal
Updated on 20-Dec-2019 11:17:22

472 Views

Given a number n; the task is to find the Mobius function of the number n.What is Mobius Function?A Mobius function is number theory function which is defined by$$\mu(n)\equiv\begin{cases}0\1\(-1)^{k}\end{cases}$$n=  0 If n has one or more than one repeated factorsn= 1 If n=1n= (-1)k  If n is product of k distinct prime numbersExampleInput: N = 17 Output: -1 Explanation: Prime factors: 17, k = 1, (-1)^k 🠠(-1)^1 = -1 Input: N = 6 Output: 1 Explanation: prime factors: 2 and 3, k = 2 (-1)^k 🠠(-1)^2 = 1 Input: N = 25 Output: 0 Explanation: Prime factor is ... Read More

Generating hash ids using uuid3() and uuid5() in Python

Pradeep Elance
Updated on 20-Dec-2019 10:40:51

2K+ Views

The universally unique identifier is a 32 bit hexadecimal number that can guarantee a unique value in a given namespace. This helps in tracking down objects created by a program or where ever python needs to handle object or data that needs large value of identifier. The UUID class defines functions that can create these values.Syntaxuuid3(namespace, string) uuid3 usesMD5 hash value to create the identifier. Uuid5(namespace, string) Uuid5 uses SHA-1 hash value to create the identifier. The namespace can be – NAMESPACE_DNS : Used when name string is fully qualified domain name. NAMESPACE_URL : Used when name string is ... Read More

Max sum of M non-overlapping subarrays of size K in C++

Narendra Kumar
Updated on 20-Dec-2019 10:39:21

294 Views

Problem statementGiven an array and two numbers M and K. We need to find sum of max M subarrays of size K (non-overlapping) in the array. (Order of array remains unchanged). K is the size of subarrays and M is the count of subarray. It may be assumed that size of array is more than m*k. If total array size is not multiple of k, then we can take partial last array.ExampleIf Given array is = {2, 10, 7, 18, 5, 33, 0}. N = 7, M = 3 and K = 1 then output will be 61 as subset ... Read More

Missing Permutations in a list in C++

Narendra Kumar
Updated on 20-Dec-2019 10:34:29

126 Views

Problem statementGiven a list of permutations of any word. Find the missing permutation from the list of permutations.ExampleIf permutation is = { “ABC”, “ACB”, “BAC”, “BCA”} then missing permutations are {“CBA” and “CAB”}AlgorithmCreate a set of all given stringsAnd one more set of all permutationsReturn difference between two setsExample Live Demo#include using namespace std; void findMissingPermutation(string givenPermutation[], size_t permutationSize) {    vector permutations;    string input = givenPermutation[0];    permutations.push_back(input);    while (true) {       string p = permutations.back();       next_permutation(p.begin(), p.end());       if (p == permutations.front())          break;     ... Read More

Missing even and odd elements from the given arrays in C++

Narendra Kumar
Updated on 20-Dec-2019 10:29:28

296 Views

Problem statementGiven two integer arrays even [] and odd [] which contains consecutive even and odd elements respectively with one element missing from each of the arrays. The task is to find the missing elements.ExampleIf even[] = {10, 8, 6, 16, 12} and odd[] = {3, 9, 13, 7, 11} then missing number from even array is 14 and from odd array is 5.AlgorithmStore the minimum and the maximum even elements from the even[] array in variables minEven and maxEvenSum of first N even numbers is N * (N + 1). Calculate sum of even numbers from 2 to minEven ... Read More

Mirror of n-ary Tree in C++

Narendra Kumar
Updated on 20-Dec-2019 10:25:57

221 Views

Problem statementGiven a Tree where every node contains variable number of children, convert the tree to its mirrorExampleIf n-ary tree is −Then it’s mirror is −Example Live Demo#include using namespace std; struct node {    int data;    vectorchild; }; node *newNode(int x) {    node *temp = new node;    temp->data = x;    return temp; } void mirrorTree(node * root) {    if (root == NULL) {       return;    }    int n = root->child.size();    if (n < 2) {       return;    }    for (int i = 0; i < ... Read More

Minimum XOR Value Pair in C++

Narendra Kumar
Updated on 20-Dec-2019 10:21:42

154 Views

Problem statementGiven an array of integers. Find the pair in an array which has minimum XOR valueExampleIf arr[] = {10, 20, 30, 40} then minimum value pair will be 20 and 30 as (20 ^ 30) = 10. (10 ^ 20) = 30 (10 ^ 30) = 20 (10 ^ 40) = 34 (20 ^ 30) = 10 (20 ^ 40) = 60 (30 ^ 40) = 54AlgorithmGenerate all pairs of given array and compute XOR their valuesReturn minimum XOR valueExample Live Demo#include using namespace std; int getMinValue(int *arr, int n) {    int minValue = INT_MAX;    for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {          minValue = min(minValue, arr[i] ^ arr[j]);       }    }    return minValue; } int main() {    int arr[] = {10, 20, 30, 40};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Advertisements