min

AWK - find min value of each row with arbitrary size

自闭症网瘾萝莉.ら 提交于 2019-11-29 12:47:29
I have a file with the lines as: 5 3 6 4 2 3 5 1 4 3 2 6 5 8 .. I want to get the min on each line, so for example with the input given above, I should get: min of first line: 2 min of second line: 1 .. How can I use awk to do this for any arbitrary number of columns in each line? If you don't mind the output using digits instead of words you can use this one liner: $ awk '{m=$1;for(i=1;i<=NF;i++)if($i<m)m=$i;print "min of line",NR": ",m}' file min of line 1: 2 min of line 2: 1 If you really do want to count in ordinal numbers: BEGIN { split("first second third fourth",count," ") } { min=$1

Java Math.min/max performance

巧了我就是萌 提交于 2019-11-29 10:58:03
问题 EDIT: maaartinus gave the answer I was looking for and tmyklebu's data on the problem helped a lot, so thanks both! :) I've read a bit about how HotSpot has some "intrinsics" that injects in the code, specially for Java standard Math libs (from here) So I decided to give it a try, to see how much difference HotSpot could make against doing the comparison directly (specially since I've heard min/max can compile to branchless asm). public static final int max ( final int a, final int b ) { if (

How do I get the MIN() of two fields in Postgres?

穿精又带淫゛_ 提交于 2019-11-29 10:29:49
问题 Let's say I have a table like this: name | score_a | score_b -----+---------+-------- Joe | 100 | 24 Sam | 96 | 438 Bob | 76 | 101 ... | ... | ... I'd like to select the minimum of score_a and score_b. In other words, something like: SELECT name, MIN(score_a, score_b) FROM table The results, of course, would be: name | min -----+----- Joe | 24 Sam | 96 Bob | 76 ... | ... However, when I try this in Postgres, I get, "No function matches the given name and argument types. You may need to add

How to Minify HTML code?

巧了我就是萌 提交于 2019-11-29 09:30:08
问题 My idea is to somehow minify HTML code in server-side, so client receive less bytes. What do I mean with "minify"? Not zipping. More like, for example, jQuery creators do with .min .js versions. In other words, I need to remove unnecessary white-spaces and new-lines, but I can't remove so much that presentation of HTML changes (for example remove white-space between actual words in paragraph). Is there any tools that can do it? I know there is HtmlPurifier. Is it able to do it? Any other

std::max() and std::min() not constexpr

心已入冬 提交于 2019-11-29 09:03:35
I just noticed that the new standard defines min(a,b) and max(a,b) without constexpr . Examples from 25.4.7, [alg.min.max]: template<class T> const T& min(const T& a, const T& b); template<class T> T min(initializer_list<T> t); Isn't this a pity? I would have liked to write char data[ max(sizeof(A),sizeof(B)) ]; instead of char data[ sizeof(A) > sizeof(B) ? sizeof(A) : sizeof(B) ]; char data[ MAX(sizeof(A),sizeof(B)) ]; // using a macro Any reason why those can not be constexpr ? Critical Update The below analysis is wrong, because it confuses one important thing . The following statement I

Most efficient way to find the greatest of three ints

别来无恙 提交于 2019-11-29 03:41:05
问题 Below is my pseudo code. function highest(i, j, k) { if(i > j && i > k) { return i; } else if (j > k) { return j; } else { return k; } } I think that works, but is that the most efficient way in C++? 回答1: To find the greatest you need to look at exactly 3 ints, no more no less. You're looking at 6 with 3 compares. You should be able to do it in 3 and 2 compares. int ret = max(i,j); ret = max(ret, k); return ret; 回答2: Pseudocode: result = i if j > result: result = j if k > result: result = k

Why does Release/Debug have a different result for std::min?

最后都变了- 提交于 2019-11-29 02:48:37
Here is the test program: void testFunc() { double maxValue = DBL_MAX; double slope = std::numeric_limits<double>::quiet_NaN(); std::cout << "slope is " << slope << std::endl; std::cout << "maxThreshold is " << maxValue << std::endl; std::cout << "the_min is " << std::min( slope, maxValue) << std::endl; std::cout << "the_min is " << std::min( DBL_MAX, std::numeric_limits<double>::quiet_NaN()) << std::endl; } int main( int argc, char* argv[] ) { testFunc(); return 0; } In Debug, I get: slope is nan maxThreshold is 1.79769e+308 the_min is nan the_min is 1.79769e+308 In Release, I get: slope is

Find the smallest amongst 3 numbers in C++ [duplicate]

≯℡__Kan透↙ 提交于 2019-11-28 22:45:17
This question already has an answer here: Simple logic problem: Finding largest and smallest number among 3 numbers 5 answers Is there any way to make this function more elegant? I'm new to C++, I don't know if there is a more standardized way to do this. Can this be turned into a loop so the number of variables isn't restricted as with my code? float smallest(int x, int y, int z) { int smallest = 99999; if (x < smallest) smallest=x; if (y < smallest) smallest=y; if(z < smallest) smallest=z; return smallest; } There's a number of improvements that can be made. You could use standard functions

Min and max value of input in angular4 application

冷暖自知 提交于 2019-11-28 21:25:24
I have an angular4 application with a form. In this one I have an input to enter a percentage. So, I want to block the input with value between 0 and 100. I tried to add min="0" and max="100" but I can yet enter an number higher than 100 or smaller than 0. template <md-input-container> <input type="number" maxlength="3" min="0" max="100" required mdInput placeholder="Charge" [(ngModel)]="rateInput" name="rateInput"> <md-error>Required field</md-error> </md-input-container> Do you know how I can do this ? I succeeded by using a form control. This is my html code : <md-input-container> <input

How to refresh a jQuery UI Slider after setting min or max values?

二次信任 提交于 2019-11-28 21:12:20
I have a ui.slider and change it's min and max values on runtime. But these changes only get reflected in the view, when I set the values afterwards too (which causes it to fire events that are not needed). In my opinion, it should refresh the view after setting min and max too. Is there a simple workaround, seems like a refresh method is missing for the slider. $("#something").slider({ range: true, values: [25, 75], min: 0, max: 100 }); $("#something").slider("option", "min", 25); // left handle should be at the left end, but it doesn't move $("#something").slider("option", "values", [25, 75]