java,arrays,recursion,max,minimum

Here is how you can visualize this problem for maximum: Your data can look like {a, b, c, d, e} you can find max using such approach max(a, max(restOfElements)) which means you need to again use max(a, max(b, max(restOfElements))) . . . max(a, max(b, max(c, max (d, max(e, nothing))))) which...

This is because you have blank line in your file. To discard those values use a generator expression or list comprehension f = open("data.txt", "r") lines = f.readlines() if lines: a = min(int(line) for line in lines if line.strip()) print a f.close() ...

One approach is to take the minimum value, then build a list of keys that are equal to it and utilise dict.viewkeys() which has set-like behaviour and remove the keys matching the minimum value from it. d = {'A': 1, 'B': 1, 'C': 1, 'D': 4} # Use .values() and...

Why don't you use 'Minimum Qty Allowed in Shopping Cart' attribute in each product ? See in the 'Inventory' tab of your product. You can also setup the tier pricing ?...

You need to compare the number against min. You are just looking for the last number which is smaller than the following number, and 3<44.

Well, it all depends on your definition of elegant. For me, an elegant solution is one that is short, clear, idiomatic and uses existing procedures (that is, it doesn't reinvent the wheel). Here's my shot: (require srfi/1) ; import `list-index` (require srfi/26) ; import `cute` (define (min-position lst) (and (not...

jquery,validation,jquery-select2,minimum,parsley.js

Solved by: Add data-parsley-cantmin="2" attribute to the select2 field Initialize the ParsleyConfig object as following window.ParsleyConfig = { validators: { cantmin: { fn: function (value, requirement) { //return value !== requirement; if ($("#campoprofesionales").val()) if($("#campoprofesionales").val().length > 1) {return true} else {return false} }, priority: 32 } }, i18n: { en: {...

java,java-8,minimum,java-stream

You can also do int min = list.stream().mapToInt(Obj::getField).min(); ...

algorithm,math,optimization,minimum

I get essentially the median. To minimize the cost function, take the derivative. To find the minimum of the cost function, find where the derivative is zero. The cost function is not continuously differentiable everywhere, but it is piecewise differentiable. Let S = the sorted numbers of A and si...

matlab,matrix,multidimensional-array,indexing,minimum

Use this for a 5D matrix - [~,ind] = min(C(:)) [ind_dim1,ind_dim2,ind_dim3,ind_dim4,ind_dim5] = ind2sub(size(C),ind) Edit 1: This is for a case where you are not exactly looking for global but dimension specific minimum values and indices. Code %%// Random data for demo C = randi(60,2,3,4,2,3); %%// Your method [C1, I1] =...

Just use filter. It was made for filtering lists: mymin :: Ord a => a -> [a] -> [a] mymin x = filter (< x) ...

javascript,input,contact,minimum

<input type="text" name="question[name]" id="question_name" onblur="this.value.split(' ').length < 2 ? alert('you need more words here') : '';" /> jsfiddle Edit to improve it: HTML code: <p> <input type="text" name="question[name]" id="question_name" onblur="CheckErrors.Name(this);" /> <span class="error"></span> </p> JS code: var CheckErrors = { Config: { Error_Strings: { Name: 'you need more words here',...

arrays,function,assembly,mips,minimum

They key here is add $a0, $a0, $t1. Consider what that will do in the case of an array with N elements: on the second iteration you'll add 1*4, on the third iteration 2*4, and so on. So on the third iteration you'd be trying to read from array +...

May be this helps library(dplyr) library(tidyr) add_rownames(df1) %>% gather(Var, Val, -x, -rowname) %>% extract(Var, into='Var', '([^0-9]*).*') %>% group_by(rowname, x, Var) %>% summarise(Mean=mean(Val), Min=min(Val), Max=max(Val)) Or using base R res <- do.call(rbind, lapply(split(names(df1)[-1], sub('\\d+$', '', names(df1)[-1])), function(x) { x1 <- df1[x] data.frame(x=df1[1],Mean=rowMeans(x1), Max=do.call(pmax, x1), Min=do.call(pmin, x1))})) data df1 <- structure(list(x =...

fortran,gfortran,minimum,fortran77

In fixed source form, a statement label should appear in columns 1 to 5. 100 and 200 are (starting in column 7) in the statement field and are taken as being part of entities' names. A name must begin with a letter....

c++,floating-point,language-lawyer,floating-point-precision,minimum

If std::numeric_limits<F>::is_iec559 is true, then the guarantees of the IEEE 754 standard apply to floating point type F. Otherwise (and anyway), minimum permitted values of symbols such as DBL_DIG are specified by the C standard, which, undisputably for the library, “is incorporated into [the C++] International Standard by reference”, as...

Here's an O(sort(K))-time algorithm. Let 1 ≤ x1 ≤ x2 ≤ … ≤ xm be the integers not missing from the set. For all i from 0 to m, let yi = x1 + x2 + … + xi be the partial sum of the first i terms. If it...

You should compile with warnings switched on. rekursiv does not always return a value. Change rekursiv( v, i + 1, n, min ); to return rekursiv( v, i + 1, n, min ); ...

Use a simple logical extraction for x>0: MIN = apply(EWMA_SD252[,2:102], 1, function(x) min(x[x>0])) ...

By minimum and maximum I assume you mean the first and last entry seen within the range. For the provided input I changed 18 to 17 so that not all "max" values were also the upper bounds of the range. Script: awk '!e{e=$1+4;} $1-e>0{print "Range " ++i , c "...

python-3.x,python-2.x,minimum,built-in

There is nothing to improve. min and max just do 123 < "xyz". In Python2 int is always less than str. In Python3 it's actually fixed, they are incomparable now (because there is actually no way to compare 42 and "dog" you know). In your case I recommend to use...

You probably want: distance = calculateHotSpot(point1, point2); .... if(distance < minDistance){ minDistance = distance; and initialize minDistance to Double.MAX_VALUE: double minDistance = Double.MAX_VALUE The original few lines does not make much sense, because minDistance < distance would never evaluates to true since you just set minDistance = distance; distance =...

list,wolfram-mathematica,minimum

An old trick used to find the minimum is to find the max of -1 times the data. data = {1, 3, 1, 3};FindPeaks[data] which gives {{2, 3}, {4, 3}} To get the minimum use negate the data FindPeaks[-data] which gives {{1, -1}, {3, -1}} The x position is correct,...

If you wanted to get the n smallest values in a dataset sorted by rank, you can do this with the order and head functions -- no need for the for loop: num <- 10 head(df[order(df$Rank),], num) # State City Value Rank # 7 State1 city7 0.1075155728 1 # 19...

arrays,matlab,matrix,indexing,minimum

First case: vector-matrix case subvals = bsxfun(@minus,A,[x y z]) [distance,index] = min(sqrt(sum(subvals.^2,2))) Second case: Two matrices case subvals = bsxfun(@minus,A,permute(B,[3 2 1])); [distances,indices] = min(sqrt(sum(subvals.^2,2)),[],3) Testing for second case: %%// Get some random data into A and B A = randi(20,8,3) B = randi(20,4,3) %%// Just to test out out...

You can extract the minimum value of a column as follows (using the variables you have indicated): e=a[:,d].min() Note that using a=min(a[:,d]) will break you out of Numpy, slowing things down (thanks for pointing this out @SaulloCastro)....