Found 33676 Articles for Programming

C++ code to find total number of digits in special numbers

Arnab Chakraborty
Updated on 11-Mar-2022 05:58:58

908 Views

Suppose, we are given an integer number k. We call a number special number if all the digits in that number are the same. For example, 1, 11, 1111 are special numbers. We count the special numbers in order 1, 11, 111, 1111, 2, 22, 222, 2222, 3, 33, 333, 3333, and so on. We have to find out the total number of digits that are in special numbers up to k. The value of k is not greater than 10000.So, if the input is like k = 9999, then the output will be 90.StepsTo solve this, we will follow ... Read More

C++ code to find out the sum of the special matrix elements

Arnab Chakraborty
Updated on 11-Mar-2022 05:56:21

508 Views

Suppose, we are given a square matrix of dimensions n * n. The following values of the matrix are called special elements −Values that are in the main diagonal.Values that are in the second diagonal.Values of the row that has exactly (n - 1 / 2) rows above it and the same number of rows below it.Values of the column that has exactly (n - 1 / 2) columns at its left and right.We find out the sum of these special values in the matrix.So, if the input is like n = 4, mat = {{1, 2, 3, 4}, {5, ... Read More

C++ code to find the area taken by boxes in a container

Arnab Chakraborty
Updated on 11-Mar-2022 05:52:30

212 Views

Suppose, we have n pairs of boxes that need to be shipped in a square-shaped container. The width of the pair of the boxes is given as a pair (a, b) and they are given in an array 'dimensions'. If we keep the width of the boxes parallel to each other, we have to find out how much area the boxes will take inside the container. We cannot stack the boxes on top of each other. We determine the minimum area required by the two boxes in the container for all the n pairs.So, if the input is like n ... Read More

C++ code to find out who won an n-round game

Arnab Chakraborty
Updated on 11-Mar-2022 05:49:01

416 Views

Suppose, there is a two-player game that has n rounds. The scores of the rounds are given in an array 'scores' where each element is of the format {P1 Score, P2 Score}. The player with the higher score wins a round, and a player wins the game if they have won more rounds; otherwise, it is declared as a draw. So, given the scores, we have to find out who has won the game.So, if the input is like n = 4, scores = {{4, 3}, {3, 2}, {5, 6}, {2, 5}}, then the output will be Draw.StepsTo solve this, ... Read More

C++ code to find out number of battery combos

Arnab Chakraborty
Updated on 11-Mar-2022 05:45:04

342 Views

Suppose, we have n batteries that can be used a maximum of 5 times. We have some devices that need three batteries and each usage of the device increases the usage count of the batteries by 1. If we have to use the devices k times, we have to find out how many battery combinations we can make to power the devices. A battery cannot be used in two devices simultaneously and a battery that has been used 5 times cannot be included. The usage count of the batteries is given in the array batt.So, if the input is like ... Read More

Convert a polynomial to Hermite_e series in Python

AmitDiwan
Updated on 11-Mar-2022 05:35:07

187 Views

To convert a polynomial to a Hermite series, use the hermite_e.poly2herme() method in Python Numpy. Convert an array representing the coefficients of a polynomial ordered from lowest degree to highest, to an array of the coefficients of the equivalent Hermite series, ordered from lowest to highest degree. The method returns a 1-D array containing the coefficients of the equivalent Hermite series. The parameter pol, is a 1-D array containing the polynomial coefficientsStepsAt first, import the required library −import numpy as np from numpy.polynomial import hermite_e as HCreate an array using the numpy.array() method −c = np.array([1, 2, 3, 4, 5])Display ... Read More

Convert a Hermite_e series to a polynomial in Python

AmitDiwan
Updated on 11-Mar-2022 05:33:16

169 Views

To convert a Hermite_e series to a polynomial, use the hermite_e.herme2poly() method in Python Numpy. Convert an array representing the coefficients of a Hermite_e series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the “standard” basis) ordered from lowest to highest degree. The method returns a 1-D array containing the coefficients of the equivalent polynomial (relative to the “standard” basis) ordered from lowest order term to highest. The parameter c, is a 1-D array containing the Hermite series coefficients, ordered from lowest order term to highest.StepsAt first, import the required ... Read More

Remove small trailing coefficients from Hermite_e polynomial in Python

AmitDiwan
Updated on 11-Mar-2022 05:31:14

176 Views

To remove small trailing coefficients from Hermite_e polynomial, use the hermite_e.hermetrim() method in Python Numpy. The method returns a 1-d array with trailing zeros removed. If the resulting series would be empty, a series containing a single zero is returned.The “Small” means “small in absolute value” and is controlled by the parameter tol; “trailing” means highest order coefficient(s), e.g., in [0, 1, 1, 0, 0] (which represents 0 + x + x**2 + 0*x**3 + 0*x**4) both the 3-rd and 4-th order coefficients would be “trimmed. The parameter c is a 1-d array of coefficients, ordered from lowest order to ... Read More

Generate a Vandermonde matrix of the Hermite_e polynomial in Python

AmitDiwan
Updated on 11-Mar-2022 05:29:16

165 Views

To generate a Vandermonde matrix of the Hermite_e polynomial, use the hermite_e.hermevander() in Python Numpy. The method returns the pseudo-Vandermonde matrix. The shape of the returned matrix is x.shape + (deg + 1, ), where The last index is the degree of the corresponding Hermite_e polynomial. The dtype will be the same as the converted x.The parameter, x returns an Array of points. The dtype is converted to float64 or complex128 depending on whether any of the elements are complex. If x is scalar it is converted to a 1-D array. The parameter, deg is the degree of the resulting ... Read More

Compute the roots of a Hermite_e series with given complex roots in Python

AmitDiwan
Updated on 11-Mar-2022 05:27:04

156 Views

To compute the roots of a Hermite_e series, use the hermite_e.hermeroots() method in Python Numpy. The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex..The parameter, c is a 1-D array of coefficients. The root estimates are obtained as the eigenvalues of the companion matrix, roots far from the origin of the complex plane may have large errors due to the numerical instability of the series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of ... Read More

Advertisements