Search Results

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

Page 40/69 | < Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >

  • Find out 20th, 30th, nth prime number. (I'm getting 20th but not 30th?) [Python]

    - by gsin
    The question is to find the 1000th prime number. I wrote the following python code for this. The problem is, I get the right answer for the 10th , 20th prime but after that each increment of 10 leaves me one off the mark. I can't catch the bug here :( count=1 #to keep count of prime numbers primes=() #tuple to hold primes candidate=3 #variable to test for primes while count<20: for x in range(2,candidate): if candidate%x==0: candidate=candidate+2 else : pass primes=primes+(candidate,) candidate=candidate+2 count=count+1 print primes print "20th prime is ", primes[-1] In case you're wondering, count is initialised as 1 because I am not testing for 2 as a prime number(I'm starting from 3) and candidate is being incremented by 2 because only odd numbers can be prime numbers. I know there are other ways of solving this problem, such as the prime number theorem but I wanna know what's wrong with this approach. Also if there are any optimisations you have in mind, please suggest. Thank You

    Read the article

  • javascript: capturing load event on LINK

    - by pgn
    hello everyone, i'm trying to attach an event handler to the load event of a link tag, to execute some code after a stylesheet has loaded. new_element = document.createElement('link'); new_element.type = 'text/css'; new_element.rel = 'stylesheet'; new_element.href = 'http://domain.tld/file.css'; new_element.addEventListener('load', function() { alert('foo'); }, false); document.getElementsByTagName('head')[0].appendChild(new_element) i have tried onreadystatechange as well new_element.onreadystatechange = function() { alert('foo'); } unfortunately neither approach results in an alert being triggered.. Furthermore, new_element.onload is null after registering a handler for the 'load' event with addEventListener.. is that normal? thanks, andrew ps: i may not use any framework in solving this

    Read the article

  • How does a programmer think?

    - by Gordon Potter
    This may be a hopelessly vague question. But I am interested to hear whatever logical thought processes people go through when learning a new concept or trying to get their brain around code they might not have ever seen before. Basically, what general steps does one take to to break down problems and what does it take to "get it"? If you were to diagram a flowchart of how your mental process works when you look at code or try to solve a problem what might it look like? What common references, tips, and mental assumptions do you find useful in problem solving? How is this different between different domains? For example in what ways is a web programmer's thought process similar or different from a traditional desktop app developer's process?

    Read the article

  • Help Auditing in Oracle

    - by enrique
    Hello everybody I need some help in auditing in Oracle. We have a database with many tables and we want to be able to audit every change made to any table in any field. So the things we want to have in this audit are: user who modified time of change occurred old value and new value so we started creating the trigger which was supposed to perform the audit for any table but then had issues... As I mentioned before we have so many tables and we cannot go creating a trigger per each table. So the idea is creating a master trigger that can behaves dynamically for any table that fires the trigger. I was trying to do it but no lucky at all....it seems that Oracle restricts the trigger environment just for a table which is declared by code and not dynamically like we want to do. Do you have any idea on how to do this or any other advice for solving this issue? thanks in advance.

    Read the article

  • Transactional isolation level needed for safely incrementing ids

    - by Knut Arne Vedaa
    I'm writing a small piece of software that is to insert records into a database used by a commercial application. The unique primary keys (ids) in the relevant table(s) are sequential, but does not seem to be set to "auto increment". Thus, I assume, I will have to find the largest id, increment it and use that value for the record I'm inserting. In pseudo-code for brevity: id = select max(id) from some_table id++ insert into some_table values(id, othervalues...) Now, if another thread started the same transaction before the first one finished its insert, you would get two identical ids and a failure when trying to insert the last one. You could check for that failure and retry, but a simpler solution might be setting an isolation level on the transaction. For this, would I need SERIALIZABLE or a lower level? Additionally, is this, generally, a sound way of solving the problem? Are the any other ways of doing it?

    Read the article

  • Huge file in Clojure and Java heap space error

    - by trzewiczek
    I posted before on a huge XML file - it's a 287GB XML with Wikipedia dump I want ot put into CSV file (revisions authors and timestamps). I managed to do that till some point. Before I got the StackOverflow Error, but now after solving the first problem I get: java.lang.OutOfMemoryError: Java heap space error. My code (partly taken from Justin Kramer answer) looks like that: (defn process-pages [page] (let [title (article-title page) revisions (filter #(= :revision (:tag %)) (:content page))] (for [revision revisions] (let [user (revision-user revision) time (revision-timestamp revision)] (spit "files/data.csv" (str "\"" time "\";\"" user "\";\"" title "\"\n" ) :append true))))) (defn open-file [file-name] (let [rdr (BufferedReader. (FileReader. file-name))] (->> (:content (data.xml/parse rdr :coalescing false)) (filter #(= :page (:tag %))) (map process-pages)))) I don't show article-title, revision-user and revision-title functions, because they just simply take data from a specific place in the page or revision hash. Anyone could help me with this - I'm really new in Clojure and don't get the problem.

    Read the article

  • How do I create a downscaled copy of an FBO in OpenGL?

    - by Jasper Bekkers
    Hi, In order to speed up some post-processing shaders I'm using, I need to perform these operations on a framebuffer that is smaller in size than the actual window (about 1/4th or more). Most of the effects I want to optimize are simple blurring operations that could be replaced (for a large part) by smaller kernel and bilinear filtering. Thus, I need to create a copy of the current FBO into another one. However, I couldn't find anything, that works, on how to do this. I've tried using glBlitframebufferEXT and rendering a fullscreen quad into the other framebuffer, but both paths result in a black texture as output. How do I go about solving this problem?

    Read the article

  • Selecting an element based on class and id in jquery - similar to an SQL query

    - by Ankur
    I want to select an element based on it's class and id, I have seen many similar questions on SO. Most of the users ask why would you ever want to do this - which is not very helpful, trust me, this is the simplest way of solving my UI problem, and it's a very unique and intereting UI related to making generic triple stores easily browsable. At the moment the jQUery looks like this: $(document).ready( function() { $(".predicates").hide(); $(".objects").hide(); $("#subject").click( function() { $("#predId, .predicates").toggle(); // this line } ); $("#predId").click( function() { $("#objId, .objects").toggle(); } ); }); The line I am really interested in is this $("#predId, .predicates").toggle(); how do I get the select to ensure that both #predId and .predicates are true, at the moment it seems that only one or the other has to be true. Is there something like an && operator?

    Read the article

  • What is the best Java numerical method package?

    - by Bob Cross
    I am looking for a Java-based numerical method package that provides functionality including: Solving systems of equations using different numerical analysis algorithms. Matrix methods (e.g., inversion). Spline approximations. Probability distributions and statistical methods. In this case, "best" is defined as a package with a mature and usable API, solid performance and numerical accuracy. Edit: derick van brought up a good point in that cost is a factor. I am heavily biased in favor of free packages but others may have a different emphasis.

    Read the article

  • Delphi 2010: how to stamp file version in *.pas and increment it on each save w/o CVS/SVN tools?

    - by FractalizeR
    Hello. How do I have in each *.pas file it's version, incrementing on each save in some comment line? I have plenty of files on three PCs and I need to have a possibility to quickly check their versions against each other. This problem is easily solved by some centralized version control, but some sources I have cannot be trusted to external servers and are kept on TrueCrypt volumes. May be some addon can do that for me? Something like changing $Version: to $Version: 121212 on each save, incrementing this value? May be there is another way also of solving this problem?

    Read the article

  • More ruby-like solution to this problem?

    - by RaouL
    I am learning ruby and practicing it by solving problems from Project Euler. This is my solution for problem 12. # Project Euler problem: 12 # What is the value of the first triangle number to have over five hundred divisors? require 'prime' triangle_number = ->(num){ (num *(num + 1)) / 2 } factor_count = ->(num) do prime_fac = Prime.prime_division(num) exponents = prime_fac.collect { |item| item.last + 1 } fac_count = exponents.inject(:*) end n = 2 loop do tn = triangle_number.(n) if factor_count.(tn) >= 500 puts tn break end n += 1 end Any improvements that can be made to this piece of code?

    Read the article

  • Alternative approach to OpenGL View on top of Camera

    - by Mr. Roland
    Hi, the traditional way of doing a camera preview background with OpenGL on the front is to take two SurfaceViews(one for the camera another for OpenGL) and stack them on top of each other. The problem is that stacking SurfaceViews is discouraged: http://groups.google.com/group/android-developers/browse_thread/thread/4850fe5c314a3dc6 So what alternatives are there? I was considering the following: Subclass GlSurfaceView, and then call set the Camera preview onto the holder of this subclass: Camera.setPreviewDisplay(mHolder); Don't use GLSurfaceView, instead create your own SurfaceView subclass where you display the Camera preview onto the holder and also draw your openGL. This would require to use OpenGL without GLSurfaceView, has anyone done this before? I'm not sure if this even is possible or makes sense, since it implies displaying the camera preview onto the holder of the surface and at the same time drawing OpenGL on the same surface. Is there any other sensible alternative to solving the problem without using two SurfaceViews? Thanks!

    Read the article

  • Re-binding an ajaxForm after content re-loads with ajax (jQuery 1.4.2)

    - by Cristian
    I'm trying to figure out why this is a problem when using jQuery 1.4.2 and not 1.3.2. This is my function: function prepare_logo_upload() { $("#logo-upload-form").ajaxForm({ //alert(responseText); success: function(responseText) { //alert(responseText); $('#profile .wrapper').html(responseText); prepare_logo_upload(); } }); } Every other live event works but can't use the .live() method because ajaxForm is a plugin. I have noticed this also for other types of binding (clicks) using the old form (re-binding after callback) Can you tell me if it is a way of solving this? This is a similar question, but due to my newbie reputation here, can't comment or ask a question there, so I'll ask a new one here. - http://stackoverflow.com/questions/2208880/jquery-bind-ajaxform-to-a-form-on-a-page-loaded-via-load Thank you!

    Read the article

  • TypeError: 'NoneType' object does not support item assignment

    - by R S John
    I am trying to do some mathematical calculation according to the values at particular index of a NumPy array with the following code X = np.arange(9).reshape(3,3) temp = X.copy().fill(5.446361E-01) ind = np.where(X < 4.0) temp[ind] = 0.5*X[ind]**2 - 1.0 ind = np.where(X >= 4.0 and X < 9.0) temp[ind] = (5.699327E-1*(X[ind]-1)**4)/(X[ind]**4) print temp But I am getting the following error Traceback (most recent call last): File "test.py", line 7, in <module> temp[ind] = 0.5*X[ind]**2 - 1.0 TypeError: 'NoneType' object does not support item assignment Would you please help me in solving this? Thanks

    Read the article

  • Are there any design-patterns specifically useful for game-development?

    - by Baelnorn
    This question's been bugging me for a long time. I've always wondered how game developers were solving certain problems or situations that are quite common in certain genres. For example, how would one implement the quests of a typical role-playing game (e.g. BG or TES)? Or how would you implement weapons with multiple stacking effects in a first-person shooter (e.g. the Shrink-gun or Freezer from DN3D)? How would you implement multiple choice options with a possibly intricate decision tree leading to several different outcomes (e.g. the mission trees in WC)? Are there any examples or other resources for that? Blogs? Books? Sourcecode?

    Read the article

  • Typical tasks/problems to demonstrate differences between programming languages

    - by Space_C0wb0y
    Somewhere some guy said (I honestly do not know where I got this from), that one should learn one programming language per year. I can see where that might be a good idea, because you learn new patterns and ways to look at the same problems by solving them in different languages. Typically, when learning a new language, I look at how certain problems are supposed to be solved in that language. My question now is, what, in you experience, are good, simple, and clearly defined tasks that demostrate the differences between programming languages. The Idea here is to have a set of tasks, that, when I solve all of them in the language I am learning, gives me a good overview of how things are supposed to be done in that language. I do not know if that is even possible, but it sure would be a useful thing to have. A typical example one often sees especially in tutorials for functional languages is the implementation of quicksort.

    Read the article

  • E.cancel loop in Visual basic

    - by Ahmed
    I am making an server control application ( simple with some buttons to start/stop the server ) And when the user wants to close the application there will be prompted an confirm box. Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Dim response As Integer response = MsgBox("Are you sure you want to stop the server", vbYesNo, "Stop Server ?") If response = vbYes Then Shell("cscript ""stop.vbs""", 1) Close() Else e.Cancel = True End If End Sub That is the code I have now. But when I start the application and close it with the X button or with "Close Window" I will be prompted with the question until I click on no, then it will close. It's a loop and it stops when you first click on yes then on no. Can someone help me with solving this ?

    Read the article

  • help with matlab and Discrete Fourier transform

    - by user504363
    Hi all I have previous experience with Matlab, but the problem that I face some problems in apply a problem in (DSP : Digital signal processing) which is not my study field, but I must finish that problems in days to complete my project. all i want is help me with method and steps of solving this problem in matlab and then I can write the code with myself. the problem is about the signal x(t) = exp(-a*t); 1) what's the Discrete Fourier transform of the sampled signal with sample rate fs 2) if a=1 and fs =1 , plot the amplitude spectrum of sampled signal 3) fix the sampling frequency at fs = 1(hz) [what's it mean ?] and plot the magnitude of the Fourier Transform of the sampled signal at various values of a thanks

    Read the article

  • set / line intersection solution

    - by Xavier
    I have two lists in python and I want to know if they intersect at the same index. Is there a mathematical way of solving this? For example if I have [9,8,7,6,5] and [3,4,5,6,7] I'd like a simple and efficient formula/algorithm that finds that at index 3 they intersect. I know I could do a search just wondering if there is a better way. I know there is a formula to solve two lines in y = mx + b form by subtracting them from each other but my "line" isn't truly a line because its limited to the items in the list and it may have curves. Any help is appreciated.

    Read the article

  • Why isnt php reading my cookie?

    - by Jason94
    at index.php i have a form to fill out some settings. the form posts to setsettings.php at setsettings.php it uses the form data and sets some cookies and redirect back to index.php. if i print_r($_COOKIE) at setsettings.php all is well. but nothing comes up at index.php, the $_COOKIE array is empty :( Does somebody know how i go about solving this? I set det setting by (setsettings.php): /* Write new cookie */ $expire = 60 * 60 * 24 * 60 + time(); // ~2 months setcookie("user_var_001", $_POST['selection'], $expire); and in index.php print_r($_COOKIE) turns up blank;

    Read the article

  • Get scrollheight cross-browser through Selenium

    - by hh354
    Hi, I'm working on a project which is using Selenium and I'd like to try to get the full web page height cross-browser and cross-platform. IE8 is being stubborn as always, is there anybody who has an idea of how to solve this? The problem: When you scroll down a page for e.g. 500px and you keep doing this until the bottom of the page, the last scroll will be less than 500px. I need to know how much this last scroll was. Two ways of solving: 1) Find the offset that has been scrolled each time (works everywhere except IE8) 2) Find the total height of the webpage I know JQuery's height() function does this but I can't use this function from Selenium RC. If you know a way of calling JQuery functions through Selenium or any other solution, please tell! Cheers, Henry

    Read the article

  • Is Work Stealing always the most appropriate user-level thread scheduling algorithm?

    - by Il-Bhima
    I've been investigating different scheduling algorithms for a thread pool I am implementing. Due to the nature of the problem I am solving I can assume that the tasks being run in parallel are independent and do not spawn any new tasks. The tasks can be of varying sizes. I went immediately for the most popular scheduling algorithm "work stealing" using lock-free deques for the local job queues, and I am relatively happy with this approach. However I'm wondering whether there are any common cases where work-stealing is not the best approach. For this particular problem I have a good estimate of the size of each individual task. Work-stealing does not make use of this information and I'm wondering if there is any scheduler which will give better load-balancing than work-stealing with this information (obviously with the same efficiency). NB. This question ties up with a previous question.

    Read the article

  • "Anagram solver" based on statistics rather than a dictionary/table?

    - by James M.
    My problem is conceptually similar to solving anagrams, except I can't just use a dictionary lookup. I am trying to find plausible words rather than real words. I have created an N-gram model (for now, N=2) based on the letters in a bunch of text. Now, given a random sequence of letters, I would like to permute them into the most likely sequence according to the transition probabilities. I thought I would need the Viterbi algorithm when I started this, but as I look deeper, the Viterbi algorithm optimizes a sequence of hidden random variables based on the observed output. I am trying to optimize the output sequence. Is there a well-known algorithm for this that I can read about? Or am I on the right track with Viterbi and I'm just not seeing how to apply it?

    Read the article

  • Find point which sum of distances to set of other points is minimal

    - by Pawel Markowski
    I have one set (X) of points (not very big let's say 1-20 points) and the second (Y), much larger set of points. I need to choose some point from Y which sum of distances to all points from X is minimal. I came up with an idea that I would treat X as a vertices of a polygon and find centroid of this polygon, and then I will choose a point from Y nearest to the centroid. But I'm not sure whether centroid minimizes sum of its distances to the vertices of polygon, so I'm not sure whether this is a good way? Is there any algorithm for solving this problem? Points are defined by geographical coordinates.

    Read the article

  • Using unmanaged code, how can I find a type that has a given custom attribute assigned to it?

    - by Andrew
    I had thought I could enumerate the types using IMetaDataImport.EnumTypeDefs and for each of the tokens returned, call IMetaDataImport.EnumCustomAttributes. This works, in so much as I get an array of mdCustomAttribute tokens. Using these tokens I can get a metadata token representing the Type of the returned custom attribute, by calling IMetaDataImport.GetCustomAttributeProps. Comparing my results against ILDASM, I can see that this matches the "CustomAttribute Type" that ILDASM reports. However, I cannot work out how to determine the "CustomAttributeName" that ILDASM reports. This is what I really want! While I would be interested in knowing how to get the CustomAttributeName, I would settle for an alternate approach to solving the problem.

    Read the article

< Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >