Daily Archives

Articles indexed Sunday March 21 2010

Page 8/85 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Trying to calculate the 10001st prime number in Java.

    - by user247679
    Greetings. I am doing Problem 7 from Project Euler. What I am supposed to do is calculate the 10001st prime number. (A prime number being a number that is only divisible by itself and one.) Here is my current program: public class Problem7 { public static void main(String args []){ long numberOfPrimes = 0; long number = 2; while (numberOfPrimes < 10001){ if(isPrime(number)){ numberOfPrimes++; } number++; } System.out.println("10001st prime: "+ number); } public static boolean isPrime(long N) { if (N <= 1) return false; else return Prime(N,N-1); } public static boolean Prime(long X,long Y) { if (Y == 1) return true; else if (X % Y == 0) return false; else return Prime(X, Y-1); } } It works okay with finding, say the 100th prime number, but when I enter very large numbers such as 10001 it causes a stack overflow. Does anyone know of a way to fix this? Thanks for reading my problem!

    Read the article

  • R: Removing object from parent environment using rm()

    - by user151410
    Hi, I am trying to remove an object from the parent environment. rm_obj <- function(obj){ a <-deparse(substitute(obj)) print (a) print(ls(envir=sys.frame(-1))) rm(a,envir=sys.frame(-1)) } > x<-c(1,2,3) > rm_obj(x) [1] "x" [1] "rm_obj" "x" Warning message: In rm(a, envir = sys.frame(-1)) : object 'a' not found This will help clarify my misunderstanding regarding frames. Thanks in advance, Russ

    Read the article

  • problem while removing an element from the TreeSet

    - by harshit
    I am doing the following class RuleObject implements Comparable{ @Override public String toString() { return "RuleObject [colIndex=" + colIndex + ", probability=" + probability + ", rowIndex=" + rowIndex + ", rule=" + rule + "]"; } String rule; double probability; int rowIndex; int colIndex; public RuleObject(String rule, double probability) { this.rule = rule; this.probability = probability; } @Override public int compareTo(Object o) { RuleObject ruleObj = (RuleObject)o; System.out.println(ruleObj); System.out.println("---------------"); System.out.println(this); if(ruleObj.probability > probability) return 1; else if(ruleObj.probability < probability) return -1; else{ if(ruleObj.colIndex == this.colIndex && ruleObj.rowIndex == this.rowIndex && ruleObj.probability == this.probability && ruleObj.rule.equals(this.rule)) return 0; } return 1; } } And I have a TreeSet containing elements of RuleObject. I am trying to do the following : System.out.println(sortedHeap.size()); RuleObject ruleObj = sortedHeap.first(); sortedHeap.remove(ruleObj); System.out.println(sortedHeap.size()); I can see that the size of set remains same. I am not able to understand why is it not being deleted. Also while deleting I could see compareTo method is called. But it is called for only 3 object whereas in set there are 8 objects. Thanks

    Read the article

  • Best current framework for unit testing EJB3 / JPA

    - by kennygrimm
    Starting new project using EJB 3 / JPA, mainly stateless session beans and batch jobs. I've used JUnit in the past on standard Java webapps and it seemed to work pretty well. In EJB2 unit testing was a pain and required a running container such as JBoss to make the calls into. Now that we're going to be working in EJB3 / JPA I'd like to know what companies are using to write and run these tests. Are Junit and JMock still considered relevant or are there other newer frameworks that have come around that we should investigate?

    Read the article

  • valueOf() vs. toString() in Javascript

    - by brainjam
    In Javascript every object has a valueOf() and toString() method. I would have thought that the toString() method got invoked whenever a string conversion is called for, but apparently it is trumped by valueOf(). For example, the code var x = {toString: function() {return "foo"; }, valueOf: function() {return 42; }}; window.console.log ("x="+x); window.console.log ("x="+x.toString()); will print x=42 x=foo This strikes me as backwards .. if x were a complex number, for example, I would want valueOf() to give me its magnitude (so that zero would become special), but whenever I wanted to convert to a string I would want something like "a+bi". And I wouldn't want to have to call toString() explicitly in contexts that implied a string. Is this just the way it is?

    Read the article

  • Resizing an image using mouse dragging (C#)

    - by Gaax
    Hi all. I'm having some trouble resizing an image just by dragging the mouse. I found an average resize method and now am trying to modify it to use the mouse instead of given values. The way I'm doing it makes sense to me but maybe you guys can give me some better ideas. I'm basically using the distance between the current location of the mouse and the previous location of the mouse as the scaling factor. If the distance between the current mouse location and the center of of the image is less than the distance between previous mouse location and the center of the image then the image gets smaller, and vice-versa. With the code below I'm getting an Argument Exception (invalid parameter) when creating the new bitmap with the new height and width and I really don't understand why... any ideas? private static Image resizeImage(Image imgToResize, System.Drawing.Point prevMouseLoc, System.Drawing.Point currentMouseLoc) { int sourceWidth = imgToResize.Width; int sourceHeight = imgToResize.Height; float dCurrCent = 0; //Distance between current mouse location and the center of the image float dPrevCent = 0; //Distance between previous mouse location and the center of the image float dCurrPrev = 0; //Distance between current mouse location and the previous mouse location int sign = 1; System.Drawing.Point imgCenter = new System.Drawing.Point(); float nPercent = 0; imgCenter.X = imgToResize.Width / 2; imgCenter.Y = imgToResize.Height / 2; // Calculating the distance between the current mouse location and the center of the image dCurrCent = (float)Math.Sqrt(Math.Pow(currentMouseLoc.X - imgCenter.X, 2) + Math.Pow(currentMouseLoc.Y - imgCenter.Y, 2)); // Calculating the distance between the previous mouse location and the center of the image dPrevCent = (float)Math.Sqrt(Math.Pow(prevMouseLoc.XimgCenter.X,2) + Math.Pow(prevMouseLoc.Y - imgCenter.Y, 2)); // Calculating the sign value if (dCurrCent >= dPrevCent) { sign = 1; } else { sign = -1; } nPercent = sign * (float)Math.Sqrt(Math.Pow(currentMouseLoc.X - prevMouseLoc.X, 2) + Math.Pow(currentMouseLoc.Y - prevMouseLoc.Y, 2)); int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); Bitmap b = new Bitmap(destWidth, destHeight); // exception thrown here Graphics g = Graphics.FromImage((Image)b); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(imgToResize, 0, 0, destWidth, destHeight); g.Dispose(); return (Image)b; }

    Read the article

  • going reverse in a for loop?

    - by sil3nt
    Hello there, Basically i got this for loop and i want the number inputed (eg. 123) to be printed out in reverse, so "321". so far it works fine and prints out the correct order when the for loop is for(i = 0; i<len ; i++) but i get an error when i try to print it in reverse?. Whats going wrong? #include <stdio.h> #include <string.h> void cnvrter(char *number); int main(){ char number[80]; printf("enter a number "); gets(number); cnvrter(number); return 0; } void cnvrter(char *number){ char tmp[80]; int i = 0,len = 0; int cnvrtd_digit = 0; len = strlen(number); printf("\nsize of input %d\n",len); for(i = len; i>len ; i--){ if ( ( number[i] >= '0' ) && ( number[i]<='9' ) ){ tmp[0] = number[i]; sscanf(tmp,"%d",&cnvrtd_digit); } printf("%d\n",cnvrtd_digit); } }

    Read the article

  • Cartesian product in Scheme

    - by John Retallack
    I've been trying to do a function that returns the Cartesian Product of n sets,in Dr Scheme,the sets are given as a list of lists,I've been stuck at this all day,I would like a few guidelines as where to start,I've wrote a pice of code but it dosen't work. (define cart-n(?(l) (if (null? l) '(()) (map (?(lst) (cons (car ( car(l))) lst)) (cart-n (cdr l) )))))

    Read the article

  • Delete backup files older than 7 days

    - by rockbala
    Using osql command, SSQL backup of a database is created. It is saved to Disk. Then renamed to match the date of the day backup was taken. All these files are saved in a single folder all the time. for example: Batch1.bat does the following 1) Created backup.bak 2) renamed to backup 12-13-2009.bak (this is done by the combination of % ~ - etc to get the date parameter) This is now automated to take backup everyday by Task scheduler in Windows. Can the batch file also be modified to delete backup files older than 7 days? if so, how ? If it is not possible via batch file, other than manually deleting the files are there any other alternatives to automate the deleting job ? Thanks in advance, Balaji S

    Read the article

  • Compile Error Using MutableClassToInstanceMap with Generics

    - by user298251
    I am getting the following compile error "The method putInstance(Class, T) in the type MutableClassToInstanceMap is not applicable for the arguments (Class, Number)" on the putInstance method call. Does anyone know what I am doing wrong?? Thanks! public class TestMutableClassToInstanceMap { public final MutableClassToInstanceMap<Number> identifiers = MutableClassToInstanceMap.create(); public static void main(String[] args) { ArrayList<Number> numbers = new ArrayList<Number>(); numbers.add(new Integer(5)); TestMutableClassToInstanceMap test = new TestMutableClassToInstanceMap(numbers); } public TestMutableClassToInstanceMap(Collection<Number> numbers){ for (Number number : numbers) { this.identifiers.putInstance(number.getClass(), number); //error here } this.identifiers.putInstance(Double.class, 5.0); // This works } }

    Read the article

  • How do I limit the CPU share of TrustedInstaller.exe on a Vista system

    - by Dan Neely
    I'm trying to fix a few low end single core desktops running Vista. In normal use they're fast enough not to be a problem. The issue is that because these machines are only on when being used, primarily for school work, windowsupdate begins installing patches it launches TrustedInstaller which in turn hogs 100% of the CPU and renders the machines all but unusable for however long it takes to patch them.

    Read the article

  • How to Become a SEO Expert Within a Short Time

    Do you want to become a SEO expert? If you are a small business owner, you will like to know more about the SEO techniques to give that additional boost to your business. There are some great resources which will help you to become a SEO expert.

    Read the article

  • SEO - "What Does it Mean?"

    Today, whether you are the searcher or the searched for on the internet, whether you are looking for personal or business reasons, SEO, or the lack of it, plays a major part in our life right now. So what exactly is SEO?

    Read the article

  • How an SEO Company Implements Search Engine Optimization

    Many of you would wonder how an SEO Company can place your site on the upper ranks of search engines to drive traffic to your page. There are plenty of resources online to help you achieve the same on your own, but their expertise enable to do so easily that shows results in the shortest possible time.

    Read the article

  • How Cheap Websites Can Save You a Ton of Money!

    OK, so you need a website, and you have already started looking at cheap websites to buy, but do you know what is actually involved in getting it set up and running, so it is ready for you to start adding content. In fact, do you even know that you need to add content or are you assuming that someone else will do this for you? So read on to find out the best way to save a ton of money by buying a cheap website.

    Read the article

  • Custom Django admin URL + changelist view for custom list filter by Tags

    - by Botondus
    In django admin I wanted to set up a custom filter by tags (tags are introduced with django-tagging) I've made the ModelAdmin for this and it used to work fine, by appending custom urlconf and modifying the changelist view. It should work with URLs like: http://127.0.0.1:8000/admin/reviews/review/only-tagged-vista/ But now I get 'invalid literal for int() with base 10: 'only-tagged-vista', error which means it keeps matching the review edit page instead of the custom filter page, and I cannot figure out why since it used to work and I can't find what change might have affected this. Any help appreciated. Relevant code: class ReviewAdmin(VersionAdmin): def changelist_view(self, request, extra_context=None, **kwargs): from django.contrib.admin.views.main import ChangeList cl = ChangeList(request, self.model, list(self.list_display), self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) cl.formset = None if extra_context is None: extra_context = {} if kwargs.get('only_tagged'): tag = kwargs.get('tag') cl.result_list = cl.result_list.filter(tags__icontains=tag) extra_context['extra_filter'] = "Only tagged %s" % tag extra_context['cl'] = cl return super(ReviewAdmin, self).changelist_view(request, extra_context=extra_context) def get_urls(self): from django.conf.urls.defaults import patterns, url urls = super(ReviewAdmin, self).get_urls() def wrap(view): def wrapper(*args, **kwargs): return self.admin_site.admin_view(view)(*args, **kwargs) return update_wrapper(wrapper, view) info = self.model._meta.app_label, self.model._meta.module_name my_urls = patterns('', # make edit work from tagged filter list view # redirect to normal edit view url(r'^only-tagged-\w+/(?P<id>.+)/$', redirect_to, {'url': "/admin/"+self.model._meta.app_label+"/"+self.model._meta.module_name+"/%(id)s"} ), # tagged filter list view url(r'^only-tagged-(P<tag>\w+)/$', self.admin_site.admin_view(self.changelist_view), {'only_tagged':True}, name="changelist_view"), ) return my_urls + urls Edit: Original issue fixed. I now receive 'Cannot filter a query once a slice has been taken.' for line: cl.result_list = cl.result_list.filter(tags__icontains=tag) I'm not sure where this result list is sliced, before tag filter is applied. Edit2: It's because of the self.list_per_page in ChangeList declaration. However didn't find a proper solution yet. Temp fix: if kwargs.get('only_tagged'): list_per_page = 1000000 else: list_per_page = self.list_per_page cl = ChangeList(request, self.model, list(self.list_display), self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, list_per_page, self.list_editable, self)

    Read the article

  • Advice for young software professional ?

    - by Guruprasad
    I recently graduated from college and joined a big reputed software company. I am wondering how would you differentiate yourself among thousands of other competitive & intelligent software engineers and programmers. I am not discounting hard work here. Rather, I would like to know how to go about the job, what things to look out for, opportunities which might about in future or advice in general.

    Read the article

  • UINavigationController Back Button not visible, but works

    - by cagreen
    I have a scenario where my UINavigationController is missing the back button (left button) but tapping the left button still seems to work. I found a similar problem posted here: http://stackoverflow.com/questions/919832/uinavigationcontrollers-back-button-disappears which was resolved by not setting the title to @"", but that's not my problem. Are there any other scenarios that would cause this behaviour? Thanks.

    Read the article

  • PDF form submission

    - by Jeff
    I have a PDF form (made in Acrobat) that has button to submit via HTTP. What I want to do it have a PHP script that will take the PDF form and e-mail it to me via attachment. What I don't want: --PDF Submit via e-mail button. This requires webmail users to save the pdf and attach it, and is just too confusing for most users. I want one-click and done. --Submit via mailto:[email protected]. Does the same thing as above. If there's a pdf on the server, I know how to use PHP's mail() function to e-mail it to someone. What I don't know how to do is process the PDF once someone hits Submit within the PDF. Does that make sense? Thanks, Jeff

    Read the article

  • Stretch array (Numpy, Python)

    - by Snej
    I have a numpy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like [[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]. Sure this is possible by looping over the large array and adding arrays of length four to the new array, but I'm curious if there is some secret 'magic' Python method doing just this :)

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >