Search Results

Search found 1725 results on 69 pages for 'equation solving'.

Page 59/69 | < Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >

  • Android OpenGL es "glDrawTexfOES" draws upside down

    - by Alle
    I'm using OpenGL for Android to draw my 2D images. Whenever I draw something using the code: gl.glViewport(aspectRatioOffset, 0, screenWidth, screenHeight); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluOrtho2D(gl, aspectRatioOffset, screenWidth + aspectRatioOffset,screenHeight, 0); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glBindTexture(GL10.GL_TEXTURE_2D, myScene.neededGraphics.get(ID).get(animationID).get(animationIndex)); crop[0] = 0; crop[1] = 0; crop[2] = width; crop[3] = height; ((GL11Ext)gl).glDrawTexfOES(x, y, z, width, height) I get an upside down result. I'v seen people solve this through doing: crop[0] = 0; crop[1] = height; crop[2] = width; crop[3] = -height; This does however hurt the logic in my application, so I would like the result to not be flipped upside down. Does anyone know why it happen, and any way of avoiding or solving it?

    Read the article

  • Reverse engineering and redistributing code from .NET Framework

    - by ToxicAvenger
    Once or twice I have been running into the following issue: Classes I want to reuse in my applications (and possibly redistribute) exist in the .NET Framework assemblies, but are marked internal or private. So it is impossible to reuse them directly. One way is to disassemble them, pick the pieces you need, put them in a different namespace, recompile (this can be some effort, but usually works quite well). My question is: Is this legal? Is this only legal for the classes of the Framework which are available as source code anyway? Is it illegal? I think that Microsoft marks them internal or private primarily so that they don't have to support them or can change the interfaces later. But some pieces - be it SharePoint or WCF - are almost impossible to properly extend by only using public classes from the apis. And rewriting everything from scratch generates a huge amount of effort, before you even start solving the problem you intended to solve. This is in my eyes not a "dirty" approach per se. The classes Microsoft ships are obviously well tested, if I reuse them under a different namespace I have "control" over them. If Microsoft changes the original implementation, my code won't be affected (some internals in WCF changed quite a bit with v4). It is not a super-clean approach. I would much prefer Microsoft making several classes public, because there are some nice classes hidden inside the framework.

    Read the article

  • MySQL: Limit rows linked to each joined row

    - by SolidSnakeGTI
    Hello, Specifications: MySQL 4.1+ I've certain situation that requires certain result set from MySQL query, let's see the current query first & then ask my question: SELECT thread.dateline AS tdateline, post.dateline AS pdateline, MIN(post.dateline) FROM thread AS thread LEFT JOIN post AS post ON(thread.threadid = post.threadid) LEFT JOIN forum AS forum ON(thread.forumid = forum.forumid) WHERE post.postid != thread.firstpostid AND thread.open = 1 AND thread.visible = 1 AND thread.replycount >= 1 AND post.visible = 1 AND (forum.options & 1) AND (forum.options & 2) AND (forum.options & 4) AND forum.forumid IN(1,2,3) GROUP BY post.threadid ORDER BY tdateline DESC, pdateline ASC As you can see, mainly I need to select dateline of threads from 'thread' table, in addition to dateline of the second post of each thread, that's all under the conditions you see in the WHERE CLAUSE. Since each thread has many posts, and I need only one result per thread, I've used GROUP BY CLAUSE for that purpose. This query will return only one post's dateline with it's related unique thread. My questions are: How to limit returned threads per each forum!? Suppose I need only 5 threads -as a maximum- to be returned for each forum declared in the WHERE CLAUSE 'forum.forumid IN(1,2,3)', how can this be achieved. Is there any recommendations for optimizing this query (of course after solving the first point)? Notes: I prefer not to use sub-queries, but if it's the only solution available I'll accept it. Double queries not recommended. I'm sure there's a smart solution for this situation. Appreciated advice in advance :)

    Read the article

  • What techniques can I employ to create a series of UI Elements from a collection of objects using WP

    - by elggarc
    I'm new to WPF and before I dive in solving a problem in completely the wrong way I was wondering if WPF is clever enough to handle something for me. Imagine I have a collection containing objects. Each object is of the same known type and has two parameters. Name (a string) and Picked (a boolean). The collection will be populated at run time. I would like to build up a UI element at run time that will represent this collection as a series of checkboxes. I want the Picked parameter of any given object in the collection updated if the user changes the selected state of the checkbox. To me, the answer is simple. I iterate accross the collection and create a new checkbox for each object, dynamically wiring up a ValueChanged event to capture when Picked should be changed. It has occured to me, however, that I may be able to harness some unknown feature of WPF to do this better (or "properly"). For example, could data binding be employed here? I would be very interested in anyone's thoughts. Thanks, E FootNote: The structure of the collection can be changed completely to better fit any chosen solution but ultimately I will always start from, and end with, some list of string and boolean pairs.

    Read the article

  • error catching exception while System.out.print

    - by user1702633
    I have 2 classes, one that implements a double lookup( int i); and one where I use that lookup(int i) in solving a question, or in this case printing the lookup values. This case is for an array. So I read the exception documentation or google/textbook and come with the following code: public double lookup(int i) throws Exception { if( i > numItems) throw new Exception("out of bounds"); return items[i]; } and take it over to my class and try to print my set, where set is a name of the object type I define in the class above. public void print() { for (int i = 0; i < set.size() - 1; i++) { System.out.print(set.lookup(i) + ","); } System.out.print(set.lookup(set.size())); } I'm using two print()'s to avoid the last "," in the print, but am getting an unhandled exception Exception (my exception's name was Exception) I think I have to catch my exception in my print() but cannot find the correct formatting online. Do I have to write catch exception Exception? because that gives me a syntax error saying invalid type on catch. Sources like http://docs.oracle.com/javase/tutorial/essential/exceptions/ are of little help to me, I'm can't seem to grasp what the text is telling me. I'm also having trouble finding sources with multiple examples where I can actually understand the coding in the examples. so could anybody give me a source/example for the above catch phrase and perhaps a decent source of examples for new Java programmers? my book is horrendous and I cannot seem to find an understandable example for the above catch phrase online.

    Read the article

  • Client Server communication in Java - which approach to use?

    - by markovuksanovic
    I have a typical client server communication - Client sends data to the server, server processes that, and returns data to the client. The problem is that the process operation can take quite some time - order of magnitude - minutes. There are a few approaches that could be used to solve this. Establish a connection, and keep it alive, until the operation is finished and the client receives the response. Establish connection, send data, close the connection. Now the processing takes place and once it is finished the server could establish a connection to the client to send the data. Establish a connection, send data, close the connection. Processing takes place. client asks server, every n minutes/seconds if the operation is finished. If the processing is finished the client fetches the data. I was wondering which approach would be the best way to use. Is there maybe some "de facto" standard for solving this problem? How "expensive" is opening a socket in Java? Solution 1. seems pretty nasty to me, but 2. and 3. could do. The problem with solution 2. is that the server needs to know on which port the client is listening, while solution 3. adds some network overhead.

    Read the article

  • Disable specific dates in jquery

    - by rvdb86
    I am using the jquery date picker found here: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.html that allows the user to pick a start and end date. However I want to be able to disable specific dates. I tried to implement the code found here: stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holida that discusses disabling national holidays. Here is my complete code: $(function() { $('.date-pick').datePicker({ beforeShowDay: nationalDays}) // $(".selector").datepicker({ beforeShowDay: nationalDays}) var natDays = [ [1, 26, 'au'], [2, 6, 'nz'], [3, 17, 'ie'], [4, 27, 'za'], [5, 25, 'ar'], [6, 6, 'se'], [7, 4, 'us'], [8, 17, 'id'], [9, 7, 'br'], [10, 1, 'cn'], [11, 22, 'lb'], [12, 12, 'ke'] ]; function nationalDays(date) { for (i = 0; i < natDays.length; i++) { if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) { return [false, natDays[i][2] + '_day']; } } return [true, '']; } $('#start-date').bind( 'dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#end-date').dpSetStartDate(d.addDays(1).asString()); } } ); $('#end-date').bind( 'dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#start-date').dpSetEndDate(d.addDays(-1).asString()); } } ); }); But this does not seem to work. I would really appreciate any assistance with solving this!

    Read the article

  • How would I include open source library in my iPhone application?

    - by greypoint
    I have found an existing open source library that I would like to include in my iPhone project (the unrar source code found here: http://www.rarlab.com/rar_add.htm ). I have compiled this source as a linked library on my Mac with "make lib" which creates the libunrar.so file just fine. These are the makefile settings for that target: lib: WHAT=RARDLL lib: $(OBJECTS) $(LIB_OBJ) @rm -f libunrar.so $(LINK) -shared -o libunrar.so $(LDFLAGS) $(OBJECTS) $(LIB_OBJ) Obviously I can't use this on iPhone but I imagine I should be able to compile with different options to make a static library that I can use. Do I: Compile it on the Mac with different make options then drag the resulting library (some kind of .a ?) into my xcode project? or Drag all of the source code into my xcode project and create special targets of some kind to create it? or Something else entirely different? I've been working on solving my unrar problem for a couple of weeks now and I believe using this library will give me the best results but I just don't know the final steps to make use of it. Thanks for all advice.

    Read the article

  • How can I build and parse HTTP URL's / URI's / paths in Perl?

    - by Robert S. Barnes
    I have a wget-like script which downloads a page and then retrieves all the files linked in IMG tags on that page. Given the URL of the original page and the the link extracted from the IMG tag in that page I need to build the URL for the image file I want to retrieve. Currently I use a function I wrote: sub build_url { my ( $base, $path ) = @_; # if the path is absolute just prepend the domain to it if ($path =~ /^\//) { ($base) = $base =~ /^(?:http:\/\/)?(\w+(?:\.\w+)+)/; return "$base$path"; } my @base = split '/', $base; my @path = split '/', $path; # remove a trailing filename pop @base if $base =~ /[[:alnum:]]+\/[\w\d]+\.[\w]+$/; # check for relative paths my $relcount = $path =~ /(\.\.\/)/g; while ( $relcount-- ) { pop @base; shift @path; } return join '/', @base, @path; } The thing is, I'm surely not the first person solving this problem, and in fact it's such a general problem that I assume there must be some better, more standard way of dealing with it, using either a core module or something from CPAN - although via a core module is preferable. I was thinking about File::Spec but wasn't sure if it has all the functionality I would need.

    Read the article

  • how close a connection from server side that created by ajax from client side

    - by saeid
    I have this sample php code: <?php function response($a) { @ob_end_clean(); header("Connection: close"); ob_start(); echo $a; $length = ob_get_length(); header("Content-Length: $length"); ob_end_flush(); flush(); } response("test1"); sleep(5); echo "test2"; ?> now I make a connection to server from client by ajax. now I want to server only send "test1" to me and then close the connection. but connection not closed and wait 5 seconds and send me "test1 test2" !! this is response headers from server to me : X-Powered-By: PHP/5.3.27 Connection: close Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Cache-Control: private, no-cache, no-store, ------revalidate, no-transform Transfer-Encoding: chunked Content-Type: text/html in response headers I do not see Content-Length header. is problem for this ?? or if not what I must do now for solving problem ??

    Read the article

  • How to best manage multi-frame MovieClips with classes?

    - by Arms
    After switching to AS3, I've been having a hell of a time figuring out the best way to manage MovieClips that have UI elements spread across multiple frames with a single class. An example that I am working on now is a simple email form. I have a MovieClip with two frames: the 1st frame has the form elements (text inputs, submit button) the 2nd frame has a "thank you" message and a button to go back to the first frame (to send another email) In the library I have linked the MovieClip to a custom class (Emailer). My immediate problem is how do I assign a MouseEvent.CLICK event to the button on the 2nd frame? I should note at this point that I am trying to avoid putting code on the timeline (except for stop() calls). This is how I am 'solving' the problem now: Emailer registers an event listener for a frame change ( addEventListener("frame 2", onFrameChange) ) On the 2nd frame of the MovieClip I am calling dispatchEvent(new Event("frame 2")); (I would prefer to not have this code on the frame, but I don't know what else to do) My two complaints with this method are that, first I have calls to addEventListener spread out across different class methods (I would rather have all UI event listeners registered in one method), and second that I have to dispatch those custom "onFrameChange" events. The second complaint grows exponentially for MovieClips that have more than just 2 frames. My so called solution feels makes me feel dirty and makes my brain hurt. I am looking for any advice on what to do differently. Perhaps there's a design pattern I should be looking at? Should I swallow my pride and write timeline code even though the rest of my application is written in class files (and I abhor the Flash IDE code editor)? I absolutely LOVE the event system, and have no problem coding applications with it, but I feel like I'm stuck thinking in terms of AS2 when working with mutl-frame movieclips and code. Any and all help would be greatly appreciated.

    Read the article

  • CSS Differences Between IE and FF

    - by Joe Majewski
    I hope I'm not breaking any rules by asking a question that pertains to a project I'm working on. If you view my page here and view it in Firefox and again in Internet Explorer, the width of the main content boxes differs. In Firefox, everything aligns perfectly with the advertisement at the top of the page, but in IE, the width of the content boxes seems to fall short by about 20 or so pixels. My question is obvious by now, but what is causing the width in IE to fall short, and what would a simple solution be? If I happen to be breaking the rules by asking a question that is not generic enough to benefit others, then allow me to rephrase it; what would be the best approach to solving visual differences between browsers? Should I use a separate CSS file for IE, or is there a way to define lines in my CSS file that only get rendered by a specific browser? It would be best if someone could provide me with the necessary CSS to align things properly, but I would be more than happy to learn about how to make the CSS dynamic (if that's possible). Thanks everyone. :)

    Read the article

  • Overlaying one div over another, but not knowing the size of the div

    - by andyuk
    I'm trying to lay one div over another. This is really simple if you know the dimensions of the div. Solved here: How to overlay one div over another div So, here is my HTML: <div class="container"> <div class="overlay"></div> <div class="content"></div> </div> In my case, I don't know the exact dimensions of the "content" or "container" div. This is because I don't have control over any of the content in the div (we are making our app extensible for 3rd party developers). See my example on jsFiddle The overlay should cover the content entirely. Width 100% and Height 100%. However, this does not work because in my example I positioned the overlay absolutely. One solution is to use JavaScript to get the size of the content div and then set the size of the overlay. I don't like this solution much since if image sizes are not specified, you need to wait until images are loaded and recalculate the size of the div. Is there any way of solving this problem in CSS? 

    Read the article

  • Make conversion to a native type explicit in C++

    - by Tal Pressman
    I'm trying to write a class that implements 64-bit ints for a compiler that doesn't support long long, to be used in existing code. Basically, I should be able to have a typedef somewhere that selects whether I want to use long long or my class, and everything else should compile and work. So, I obviously need conversion constructors from int, long, etc., and the respective conversion operators (casts) to those types. This seems to cause errors with arithmetic operators. With native types, the compiler "knows" that when operator*(int, char) is called, it should promote the char to int and call operator*(int, int) (rather than casting the int to char, for example). In my case it gets confused between the various built-in operators and the ones I created. It seems to me like if I could flag the conversion operators as explicit somehow, that it would solve the issue, but as far as I can tell the explicit keyword is only for constructors (and I can't make constructors for built-in types). So is there any way of marking the casts as explicit? Or am I barking up the wrong tree here and there's another way of solving this? Or maybe I'm just doing something else wrong...

    Read the article

  • Prevent hash navigation url

    - by Koningh
    I have the following problem: I'm using a slider (coda) to let people navigate trough some 'pages'. The slider uses hash links to navigate to the next page/slide. If a user is at page one (#page1), there is a link which will lead the user to page 2 (#page2) and so on. At the top of the slider the numbers of the pages appear as a link, but only when the page is visited. So if there are six pages and the user navigates from the first to the second and then the third one, there are only three links at the top of the slider (to page one, two and three). The problem is that a user can navigate to page five (or any page actually) without first visiting the pages previous to page five by just using the hash URL and typing the whole link in their address bar. For example if I would type www.mydomain.com/slider/index.php#page5 the slider automatically navigates to the fifth slide/page of the slider and thereby skipping the first four. I want to allow users to navigate to #page5 only if they have visited the first four (So by clicking trough the slides). This means that if they would go to #page5 directly by typing the URL in the address bar, I would like them to be send to the first page (#page1). Does anyone have any idea on solving this?

    Read the article

  • Rails dealing with blank params at controller level

    - by stephenmurdoch
    I have a User model: class User < ActiveRecord::Base has_secure_password # validation lets users update accounts without entering password validates :password, presence: { on: :create }, allow_blank: { on: :update } validates :password_confirmation, presence: { if: :password_digest_changed? } end I also have a password_reset_controller: def update # this is emailed to the user by the create action - not shown @user=User.find_by_password_reset_token!(params[:id]) if @user.update_attributes(params[:user]) # user is signed in if password and confirmation pass validations sign_in @user redirect_to root_url, :notice => "Password has been reset." else flash.now[:error] = "Something went wrong, please try again." render :edit end end Can you see the problem here? A user can submit a blank a password/confirmation and rails will sign them in, because the User model allows blank on update. It's not a security concern, since an attacker would still need access to a user's email account before they could get anywhere near this action, but my problem is that a user submitting 6 blank chars would be signed in, and their password would not be changed for them, which could lead to confusion later on. So, I've come up with the following solution, and I'd like to check if there's a better way of doing it, before I push to production: def update @user=User.find_by_password_reset_token!(params[:id]) # if user submits blank password, add an error, and render edit action if params[:user][:password].blank? @user.errors.add(:password_digest, "can't be blank.") render :edit elsif @user.update_attributes(params[:user]) sign_in @user redirect_to root_url, :notice => "Password has been reset." else flash.now[:error] = "Something went wrong, please try again." render :edit end end Should I be checking for nil as well as blank? Are there any rails patterns or idiomatic ruby techniques for solving this? [Fwiw, I've got required: true on the html inputs, but want this handled server side too.]

    Read the article

  • In Rails 3, how does one render HTML within a JSON response?

    - by ylg
    I'm porting an application from Merb 1.1 / 1.8.7 to Rails 3 (beta) / 1.9.1 that uses JSON responses containing HTML fragments, e.g., a JSON container specifying an update, on a user record, and the updated user row looks like . In Merb, since whatever a controller method returns is given to the client, one can put together a Hash, assign a rendered partial to one of the keys and return hash.to_json (though that certainly may not be the best way.) In Rails, it seems that to get data back to the client one must use render and render can only be called once, so rendering the hash to json won't work because of the partial render. From reading around, it seems one could put that data into a JSON .erb view file, with <%= render partial % in and render that. Is there a Rails-way of solving this problem (return JSON containing one or more HTML fragments) other than that? In Merb: only_provides :json ... self.status = 204 # or appropriate if not async return { 'action' => 'update', 'type' => 'user', 'id' => @user.id, 'html' => partial('user_row', format: :html, user: @user) }.to_json In Rails?

    Read the article

  • PHP include taking too long

    - by wxiiir
    I have a php file with around 100mb which is full of arrays (only arrays). I've made a script that includes this file (for processing), first it exhausted the default Xampp 128mb memory limit, i've raised it to 1024mb but it just takes forever and doesn't do anything. I'm sure the problem is being created by the sheer size of the file because i've tried removing all lines of code and just leaving the include and an echo for me to know when it finishes executing, and it does the same thing (which is taking forever), i've also tried to run the 100mb file in separate and same thing again. A 10mb file is taking forever as well but a similar 1mb file is almost instantly read and executed so the problem must be more than just the file size. I was avoiding using c++ for a simple project as this and would rather not to as php is easier for me and the task that will be executed doesn't need to benefit from the added speed that it would have if it had been done in c++ but if i have no luck in solving this problem i guess i'll have to. EDIT Reasons for not using a database: 1-Whoever made it didn't used a database and it will be pretty hard to store this in an organized database if i'm not able to do something with it first, like just reading it, copying parts from it or putting in memory or something. 2-I don't have experience working with databases as pretty much all stuff i've ever done in php didn't needed large amounts of stored data, 50kb at best, if i was thinking about a big project or huge chunks of data as this one, i definitely would, but i didn't made this mess to start with and now i have to undo it. 3-The logic for having to store a small portion of data like 10mb in hard drive when now every computer has pretty much enough ram to fit the whole OS in it is pretty much incomprehensible unless someone gives a good explanation about it, if i had to access a lot of said files simultaneously i would understand but like i said, this is a simple project, this is the only file that will be accessed at a given time this isn't even to make some kind of website, it's to run a few times and be done with it.

    Read the article

  • What choices do I have for a future in software development?

    - by user354892
    After graduating from college with a degree in mathematics and a minor in computer science, I took over a year to find my first programming job. I very much enjoy my work environment, but sometimes I feel like I'm not developing professionally as quickly as I am capable of. My company does mostly web programming. The project that I work on is basically a front-end for a SQL database. The entire project is (AFAIK) coded is VB.NET. I've been working on the back-end logic of the program. After some time on the job, we decided that designing web pages is not my cup of tea. It seems like the thing that I spend more time on than anything else is searching the web and SO for information about poorly documented .net and web APIs. This does not make me happy; is this normal for a programming job; I don't think it is. It really hit me the other day when i saw a question about math asked here and I didn't know the answer; I feel like my knowledge is going stale! I was previously almost hired by another company where they design graphic-intensive battle simulations for the military. I sometimes wonder what my life might be like if I had that job. I feel like my math and problem solving skills might have been a better fit at this other company. Within the wide field of software development, there are a number of directions in which to go as evidenced by the huge variety of topics discussed here on StackOverflow. I would like to feel like I'm going in the direction where I will make the most of my skills and have a satisfying career. Let me word this question as clearly as possible: given the wide breadth of the field of software development, how does it break down into sub-fields and what are the considerations for developing a software development career. I do not want to manage my career by default.

    Read the article

  • Is a python dictionary the best data structure to solve this problem?

    - by mikip
    Hi I have a number of processes running which are controlled by remote clients. A tcp server controls access to these processes, only one client per process. The processes are given an id number in the range of 0 - n-1. Were 'n' is the number of processes. I use a dictionary to map this id to the client sockets file descriptor. On startup I populate the dictionary with the ids as keys and socket fd of 'None' for the values, i.e no clients and all pocesses are available When a client connects, I map the id to the sockets fd. When a client disconnects I set the value for this id to None, i.e. process is available. So everytime a client connects I have to check each entry in the dictionary for a process which has a socket fd entry of None. If there are then the client is allowed to connect. This solution does not seem very elegant, are there other data structures which would be more suitable for solving this? Thanks

    Read the article

  • SQL: Limit rows linked to each joined row

    - by SolidSnakeGTI
    Hello, I've certain situation that requires certain result set from MySQL query, let's see the current query first & then ask my question: SELECT thread.dateline AS tdateline, post.dateline AS pdateline, MIN(post.dateline) FROM thread AS thread LEFT JOIN post AS post ON(thread.threadid = post.threadid) LEFT JOIN forum AS forum ON(thread.forumid = forum.forumid) WHERE post.postid != thread.firstpostid AND thread.open = 1 AND thread.visible = 1 AND thread.replycount >= 1 AND post.visible = 1 AND (forum.options & 1) AND (forum.options & 2) AND (forum.options & 4) AND forum.forumid IN(1,2,3) GROUP BY post.threadid ORDER BY tdateline DESC, pdateline ASC As you can see, mainly I need to select dateline of threads from 'thread' table, in addition to dateline of the second post of each thread, that's all under the conditions you see in the WHERE CLAUSE. Since each thread has many posts, and I need only one result per thread, I've used GROUP BY CLAUSE for that purpose. This query will return only one post's dateline with it's related unique thread. My questions are: How to limit returned threads per each forum!? Suppose I need only 5 threads -as a maximum- to be returned for each forum declared in the WHERE CLAUSE 'forum.forumid IN(1,2,3)', how can this be achieved. Is there any recommendations for optimizing this query (of course after solving the first point)? Notes: I prefer not to use sub-queries, but if it's the only solution available I'll accept it. Double queries not recommended. I'm sure there's a smart solution for this situation. I'm using MySQL 4.1+, but if you know the answer for another engine, just share. Appreciated advice in advance :)

    Read the article

  • Given a 2d array sorted in increasing order from left to right and top to bottom, what is the best w

    - by Phukab
    I was recently given this interview question and I'm curious what a good solution to it would be. Say I'm given a 2d array where all the numbers in the array are in increasing order from left to right and top to bottom. What is the best way to search and determine if a target number is in the array? Now, my first inclination is to utilize a binary search since my data is sorted. I can determine if a number is in a single row in O(log N) time. However, it is the 2 directions that throw me off. Another solution I could use, if I could be sure the matrix is n x n, is to start at the middle. If the middle value is less than my target, then I can be sure it is in the left square portion of the matrix from the middle. I then move diagnally and check again, reducing the size of the square that the target could potentially be in until I have honed in on the target number. Does anyone have any good ideas on solving this problem? Example array: Sorted left to right, top to bottom. 1 2 4 5 6 2 3 5 7 8 4 6 8 9 10 5 8 9 10 11

    Read the article

  • Best way to get distinct values from large table

    - by derivation
    I have a db table with about 10 or so columns, two of which are month and year. The table has about 250k rows now, and we expect it to grow by about 100-150k records a month. A lot of queries involve the month and year column (ex, all records from march 2010), and so we frequently need to get the available month and year combinations (ie do we have records for april 2010?). A coworker thinks that we should have a separate table from our main one that only contains the months and years we have data for. We only add records to our main table once a month, so it would just be a small update on the end of our scripts to add the new entry to this second table. This second table would be queried whenever we need to find the available month/year entries on the first table. This solution feels kludgy to me and a violation of DRY. What do you think is the correct way of solving this problem? Is there a better way than having two tables?

    Read the article

  • Given a vector of maximum 10 000 natural and distinct numbers, find 4 numbers(a, b, c, d) such that

    - by king_kong
    Hi, I solved this problem by following a straightforward but not optimal algorithm. I sorted the vector in descending order and after that substracted numbers from max to min to see if I get a + b + c = d. Notice that I haven't used anywhere the fact that elements are natural, distinct and 10 000 at most. I suppose these details are the key. Does anyone here have a hint over an optimal way of solving this? Thank you in advance! Later Edit: My idea goes like this: '<<quicksort in descending order>>' for i:=0 to count { // after sorting, loop through the array int d := v[i]; for j:=i+1 to count { int dif1 := d - v[j]; int a := v[j]; for k:=j+1 to count { if (v[k] > dif1) continue; int dif2 := dif1 - v[k]; b := v[k]; for l:=k+1 to count { if (dif2 = v[l]) { c := dif2; return {a, b, c, d} } } } } } What do you think?(sorry for the bad indentation)

    Read the article

  • C++ - Totally suspend windows application

    - by HardCoder1986
    Hello! I am developing a simple WinAPI application and started from writing my own assertion system. I have a macro defined like ASSERT(X) which would make pretty the same thing as assert(X) does, but with more information, more options and etc. At some moment (when that assertion system was already running and working) I realized there is a problem. Suppose I wrote a code that does some action using a timer and (just a simple example) this action is done while handling WM_TIMER message. And now, the situation changes the way that this code starts throwing an assert. This assert message would be shown every TIMER_RESOLUTION milliseconds and would simply flood the screen. Options for solving this situation could be: 1) Totally pause application running (probably also, suspend all threads) when the assertion messagebox is shown and continue running after it is closed 2) Make a static counter for the shown asserts and don't show asserts when one of them is already showing (but this doesn't pause application) 3) Group similiar asserts and show only one for each assert type (but this also doesn't pause application) 4) Modify the application code (for example, Get / Translate / Dispatch message loop) so that it suspends itself when there are any asserts. This is good, but not universal and looks like a hack. To my mind, option number 1 is the best. But I don't know any way how this can be achieved. What I'm seeking for is a way to pause the runtime (something similiar to Pause button in the debugger). Does somebody know how to achieve this? Also, if somebody knows an efficient way to handle this problem - I would appreciate your help. Thank you.

    Read the article

< Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >