Programming Articles

Page 301 of 2544

How to add named vectors of different sizes based on names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 285 Views

If we have named vectors but the names come from same family then they cannot be added to each other direct to get the sum of values based on names. To do this, we need to use tapply function. For example, if we have three vectors defined as x, y, and z then firstly they need to be combined as V

Read More

PHP AssertionError

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 350 Views

IntroductionAssertionError class is a subclass of Error class. This type of error is thrown when assert() returns FALSEassert() checks if given assertion is true or false, and throws AssertionError if it is false. The assert() function is defined as follows −Syntaxfor PHP 5 and PHP 7 assert ( mixed $assertion [, string $description ] ) : bool PHP 7 only assert ( mixed $assertion [, Throwable $exception ] ) : boolParametersSr.NoParameter & Description1assertionstring or boolean expression2descriptionfailure mssage3exception (for PHP 7 only)throwable objectSince PHP 7.0, assert() is now a language construct and not a function. assertion parameter can now be an expression ...

Read More

PHP ArithmeticError

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 325 Views

IntroductionArithmeticError class is inherited from Error class. This type of error may occurwhile performing certain mathemetical operations. One such scenario is attempt to perform bitwise shift operation by negative amount. This error is also thrown when call to intdiv() function results in value such that it is beyond legitimate boundaries of integer.ArithmeticError ExampleIn Following example, an attempt is made to use binary shift operator with negative operand. This results in ArithmeticError.ExampleOutputThis will produce following result −Bit shift by negative numberIf call to intdiv() function results in invalid integer, ArithmeticError is thrown. As shown in the example below, the minimum allowed integer in ...

Read More

Program to find length of contiguous strictly increasing sublist in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 258 Views

Suppose we have a list of numbers called nums, we have to find the maximum length of a contiguous strictly increasing sublist when we can remove one or zero elements from the list.So, if the input is like nums = [30, 11, 12, 13, 14, 15, 18, 17, 32], then the output will be 7, as when we remove 18 in the list we can get [11, 12, 13, 14, 15, 17, 32] which is the longest, contiguous, strictly increasing sublist, and its length is 7.To solve this, we will follow these steps−n := size of numspre := a list ...

Read More

How to calculate two period moving average for vector elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 241 Views

If we want to find the two−period moving average easily then it cannot be done in base R. We need to use rollmean function of zoo package that solves this problem in a single line of code. For example, if we have a vector x that contains hundred from starting from 1 to 100 then the two−period moving for x can be found by using rollmean(x,2)Loading zoo package −library(zoo)Examplesx1

Read More

PHP ArgumentCountError

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 587 Views

IntroductionPHP parser throws ArgumentCountError when arguments passed to a user defined function or method are less than those in its definition. ArgumentCountError class is inherited from TypeError classArgumentCountError ExampleIn Following example, a user defined function add() is defined to receive two arguments. However, if less than required number of arguments is provided while calling, ArgumentCountError will be thrown which can be handled with catch block.ExampleOutputThis will produce following result −Too few arguments to function add(), 1 passed in C:\xampp\php\test.php on line 6 and exactly 2 expectedIn Following example, setdata() method in myclass is defined to have two formal arguments. When ...

Read More

Program to count how many times we can find "pizza" with given string characters in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 226 Views

Suppose we have a lowercase string s, we have to find how many "pizza" strings we can make using the characters present in s. We can use the characters in s in any order, but each character can be used once.So, if the input is like "ihzapezlzzilaop", then the output will be 2.To solve this, we will follow these steps −p_freq := Frequency of 'p' in si_freq := Frequency of 'i' in sz_freq := Frequency of 'z' in sa_freq := Frequency of 'a' in sreturn minimum of (p_freq, i_freq, z_freq/2 and a_freq)Let us see the following implementation to get better ...

Read More

PHP ArrayAcccess interface

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 357 Views

IntroductionIn PHP, ArrayAccess interface is used to develop a class that provides array like access to one of properties which is an array. Such array property may be manipulated without exposing it during object creation. ArrayAccess interface defines following abstract methodsSyntaxArrayAccess {    /* Methods */    abstract public offsetExists ( mixed $offset ) : bool    abstract public offsetGet ( mixed $offset ) : mixed    abstract public offsetSet ( mixed $offset , mixed $value ) : void    abstract public offsetUnset ( mixed $offset ) : void }MethodsArrayAccess::offsetExists − Whether an offset existsArrayAccess::offsetGet − Offset to retrieveArrayAccess::offsetSet − Assign ...

Read More

How to find total of an integer column based on two different character columns in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 156 Views

The calculation of total for integer column based on two different character columns simply means that we need to create a contingency table for the available data. For this purpose, we can use with and tapply function. For example, if we have a data frame df that contains two categorical columns defined as gender and ethnicity and an integer column defined as Package then the contingency table can be created as:with(df,tapply(Package,list(gender,ethnicity),sum))ExampleConsider the below data frame −set.seed(777) Class

Read More

Program to split a list of numbers such that the absolute difference of median values are smallest in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 196 Views

Suppose we have a list of numbers called nums, we have to divide it into two parts of same size where the absolute difference between each list's median is as small as possible and we have to find this difference. We have to keep in mind that here length of nums / 2 will be odd.So, if the input is like [2, 10, 8, 5, 4, 7], then the output will be 2, as we can make two lists like [2, 5, 10] and [4, 7, 8], then the medians are 5 and 7, their difference is 2.To solve this, ...

Read More
Showing 3001–3010 of 25,433 articles
« Prev 1 299 300 301 302 303 2544 Next »
Advertisements