logic

paging like stackoverflow's

只愿长相守 提交于 2019-12-04 15:43:43
问题 i'm a newbie in php especially on making pagination. my question is, how to make paging like stackoverflow's pagination? i mean paging like this : 1 ... 5 6 7 8 9 ... 25 (the first number and the last number is always appear, but in the middle only 5 numbers with the selected page absolutely in the middle) in php i have tried making paging, <?php //Show page links for($i=1; $i<=$pages; $i++) { echo '<li id="'.$i.'">'.$i.'</li>'; } ?> but it will be shown all of pages like 1 2 3 4 5 6 7 8 9 10

Fastest way to get sign in Java?

我是研究僧i 提交于 2019-12-04 15:13:11
问题 I'd like to get the sign of a float value as an int value of -1 or 1. Avoiding conditionals is always a good idea in reducing computational cost. For instance, one way I can think of would be to use a fast bit-shift to get the sign: float a = ...; int sign = a >> 31; //0 for pos, 1 for neg sign = ~sign; //1 for pos, 0 for neg sign = sign << 1; //2 for pos, 0 for neg sign -= 1; //-1 for pos, 1 for neg -- perfect. Or more concisely: int sign = (~(a >> 31) << 1) - 1; Does this seem like a good

Propositional Logic - Reducing the Number of Operations

混江龙づ霸主 提交于 2019-12-04 14:49:12
In short, I'm wondering if, given two propositional formulas, whether there is a standard method for finding the shortest sequence of operations that still have the same output as the two formulas. For example if we have the following formulas: and we can reduce the number of operations by introducing a new proposition: and then Q becomes: This reduced the number of operations (unary and binary) from 19 to 14 . The new logic circuit for Q is: Ideally I would like there to be only negations and disjunctions. Is there an algorithm for converting any proposition into my ideal simplified one? And

Login system concept & logic?

眉间皱痕 提交于 2019-12-04 12:35:19
问题 I want to know the process which usually web apps follow to maintain login between multiple requests and also how they manage things using COOKIES. In my login form I am providing "Remember Me" feature. When user login then I check the username and password validity from database. If its valid then I check if "Remember me" is selected, if yes then storing username and password in session, encrypted format. And finally storing username and password in SESSION. When user navigates form one page

Determine the sign of a 32 bit int

微笑、不失礼 提交于 2019-12-04 12:05:07
问题 Using ONLY: ! ~ & ^ | + << >> NO LOOPS I need to determine the sign of a 32 bit integer and I need to return 1 if positive, 0 if 0 and -1 if negative. Any ideas? I first thought about shifting over 31 bits and then looking at that sign but that obviously wont work and now I am kind of stuck. 回答1: Try this: (x >> 31) | (((0 - x) >> 31) & 1) How about this: (x >> 31) | (((~x + 1) >> 31) & 1) EDIT 2: In response to issues (or rather nit-picking) raised in the comments... Assumptions for these

Ford-Fulkerson algorithm with “weighted” edges

纵然是瞬间 提交于 2019-12-04 11:22:39
Is there any variation of the Ford-Fulkerson that adds an extra dimension of "weight" to the edges? By that, I mean some edges are more ideal than others, and while all the possibilities are there, it will prioritize the ideal edges over the lesser ideal edges. There are two common generalisations that I know of to add weights. Min cost flow Suppose you had a weight for each edge and wanted to compute the flow that satisfied the constraints and had minimum cost. (Cost = sum of weight * units flowing along associated edge) This problem is called minimum cost flow . An implementation can be

Backbone Routers: wait for data to be fetched first

北城以北 提交于 2019-12-04 10:48:57
问题 I think I don’t quite get the idea behind the proper usage of Backbone routers. Here’s what I’ve got: I have some data that I fetch from the server when the page loads and then pack it into models and collections. The number of those models and collections is indefinite. I want to use the router to be able to render the certain collection’s view directly from the start. The problem is: Backbone router starts up early, and since I ask it to access a certain view and trigger its render action,

How to calculate scores?

↘锁芯ラ 提交于 2019-12-04 10:40:31
问题 This question is more related to logic than any programming language. If the question is not apt for the forum please do let me know and I will delete this. I have to write a logic to calculate scores for blogs for a Blog Award website. A blog may be nominated for multiple award categories and is peer-reviewed or rated by a Jury on a -1 to 5 scale (-1 to indicate a blog they utterly dislike). Now, a blog can be rated by one or more Jurors. One criterion while calculating final score for a

Can someone explain this JavaScript auto executing function?

不羁的心 提交于 2019-12-04 09:16:43
问题 var foo = (function(){ var x = 0; return function(){return x++;}; })() Why the var x = 0 expression only runs once is my biggest misunderstanding about this. 回答1: Your code: var foo = (function(){ var x = 0; return function(){return x++;}; })() is equivalent to this code: function f(){ var x = 0; return function(){return x++;}; } var foo = f(); It's easy to see, when you break it up like this, that the function f() is only called once. It defines x , and then returns a new function that is

Converting string array to hashmap [duplicate]

泄露秘密 提交于 2019-12-04 07:16:57
This question already has an answer here: Converting string arrays into Map 5 answers I have the following response T2269|175@@2a1d2d89aa96ddd6|45464047 By using the split("\\|") i have converted into string array object. The meaning for the each field is as follows: T2269 id 175@@2a1d2d89aa96ddd6 cid 45464047 refno No i have to convert it into HashMap object . Is their any solution for the above.. The above response is given for example. In real, the length of the string array object is 36. final String[] fields = input.split("\\|"); final Map<String, String> m = new HashMap<String, String>()