Search Results

Search found 4955 results on 199 pages for 'range'.

Page 54/199 | < Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >

  • Python: Why is IDLE so slow?

    - by Adam Matan
    Hi, IDLE is my favorite Python editor. It offers very nice and intuitive Python shell which is extremely useful for unit-testing and debugging, and a neat debugger. However, code executed under IDLE is insanely slow. By insanely I mean 3 orders of magnitude slow: bash time echo "for i in range(10000): print 'x'," | python Takes 0.052s, IDLE import datetime start=datetime.datetime.now() for i in range(10000): print 'x', end=datetime.datetime.now() print end-start Takes: >>> 0:01:44.853951 Which is roughly 2,000 times slower. Any thoughts, or ideas how to improve this? I guess it has something to do with the debugger in the background, but I'm not really sure. Adam

    Read the article

  • Call methods in main method

    - by Niloo
    this is my main method that gets 3 integers from command line and I parse then in my validating method. However I have one operation method that calls 3 other methods, but i don't know what type of data and howmany I have to put in my operatinMethod() " cuase switch only gets one); AND also in my mainMethod() for calling the operationMehod(); itself? please let me know if i'm not clear? Thanx! main method: public class test { // Global Constants final static int MIN_NUMBER = 1; final static int MAX_PRIME = 10000; final static int MAX_FACTORIAL = 12; final static int MAX_LEAPYEAR = 4000; //Global Variables static int a,b,c; public static void main (String[] args) { for(int i =0; i< args.length; i++){} if(validateInput(args[0],args[1],args[2])){ performOperations(); } } //Validate User Input public static boolean validateInput(String num1,String num2,String num3){ boolean isValid = false; try{ try{ try{ a = Integer.parseInt(num1); if(!withinRange(a,MIN_NUMBER, MAX_PRIME)) { System.out.println("The entered value " + num1 +" is out of range [1 TO 10000]."); } isValid = true; } catch(Exception ex) { System.out.println("The entered value " + num1 + " is not a valid integer. Please try again."); } b = Integer.parseInt(num2); if(!withinRange(b,MIN_NUMBER, MAX_FACTORIAL)) { System.out.println("The entered value " + num2 +" is out of range [1 TO 12]."); } isValid = true; } catch(Exception ex) { System.out.println("The entered value " + num2 + " is not a valid integer. Please try again."); } c = Integer.parseInt(num3); if(!withinRange(c,MIN_NUMBER, MAX_LEAPYEAR)) { System.out.println("The entered value " + num3 +" is out of range [1 TO 4000]."); } isValid = true; } catch(Exception ex) { System.out.println("The entered value " + num3 + " is not a valid integer. Please try again."); } return isValid; } //Check the value within the specified range private static boolean withinRange(int userInput ,int min, int max){ boolean isInRange = true; if(userInput < min || userInput > max){ isInRange = false; } return isInRange; } //Perform operations private static void performOperations(int userInput) { switch(userInput) { case 1: // count Prime numbers countPrimes(a); break; case 2: // Calculate factorial getFactorial(b); break; case 3: // find Leap year isLeapYear(c); break; } } // Verify Prime Number private static boolean isPrime(int prime) { for(int i = 2; i <= Math.sqrt(prime) ; i++) { if ((prime % i) == 0) { return false; } } return true; } // Calculate Prime private static int countPrimes(int userInput){ int count =0; for(int i=userInput; i<=MAX_PRIME; i++) { if(isPrime(i)){ count++; } } System.out.println("Exactly "+ count + " prime numbers exist between "+ a + " and 10,000."); return count; } // Calculate the factorial value private static int getFactorial(int userInput){ int ans = userInput; if(userInput >1 ){ ans*= (getFactorial(userInput-1)); //System.out.println("The value of "+ b +"! is "+ getFactorial(userInput)); } return ans; } // Determine whether the integer represents a leap year private static boolean isLeapYear(int userInput){ if (userInput % 4 == 0 && userInput % 400 == 0 && userInput % 100 ==0){ System.out.println("The year "+ c +" is a leap year"); } else { System.out.println("The year "+ c +" is a not leap year"); } return false; } }

    Read the article

  • Csharp component which generates fragmens with highlights for diffs for 2 strings

    - by MicMit
    I need C# equivalent ( ideally open source ) which is similar to Delphi DLL. I am currently using the wrapper ( C# syntax is provided , but it is a call from a different language ) zdiff( string ref str1, string ref str2, int range , int trim ) it calls inside str1 = GetHiDiff(@str1,1,trim) str2 = GetHiDiff(@str1,2,trim) where function GetHiDiff(s:pchar; sIndex:integer; wtrim:integer): pchar; stdcall; What it does it returns a left fragment html of str1 and a right html fragment of str2 with diffs highlighted as strings are passed by reference. Range parameter determines the size of html fragment. Not sure what trim 0 does.

    Read the article

  • how to load an image to a grid using pygame, instead of just using a fill color?

    - by yao jiang
    I am trying to create a "map of a city" using pygame. I want to be able to put images of buildings in specific grid coords rather than just filling them in with a color. This is how I am creating this map grid: def clear(): for r in range(rows): for c in range(rows): if r%3 == 1 and c%3 == 1: color = brown; grid[r][c] = 1; else: color = white; grid[r][c] = 0; pygame.draw.rect(screen, color, [(margin+width)*c+margin, (margin+height)*r+margin, width, height]) pygame.display.flip(); Now how do I put images of buildings in those brown colored grids at those specific locations? I've tried some of the samples online but can't seem to get them to work. Any help is appreciated. If anyone have a good source for free sprites that I can use for pygame, please let me know. Thanks!

    Read the article

  • Apache POI HWPF Nested Lists?

    - by Mahadevan
    Hi, I used the following code to read list structures from a word file using hwpf. My question is how to read a list structure that is nested ie a list within a list within a list and so on. if (p instanceof ListEntry) { ListEntry entry = (ListEntry) p; outText = entry.text(); outText = "<li>" + outText + "</li>"; // verifca prima e ultimo if (i > 1) { pPrev = range.getParagraph(i - 1); if (!(pPrev instanceof ListEntry)) outText = "<ul>" + outText; } if (i < nParagrafi - 1) { pNext = range.getParagraph(i + 1); if (!(pNext instanceof ListEntry)) outText = outText + "</ul>"; } if (i == nParagrafi - 1) { outText = outText + "</ul>"; }

    Read the article

  • Fastest way to list all primes below N in python

    - by jbochi
    This is the best algorithm I could come up with after struggling with a couple of Project Euler's questions. def get_primes(n): numbers = set(range(n, 1, -1)) primes = [] while numbers: p = numbers.pop() primes.append(p) numbers.difference_update(set(range(p*2, n+1, p))) return primes >>> timeit.Timer(stmt='get_primes.get_primes(1000000)', setup='import get_primes').timeit(1) 1.1499958793645562 Can it be made even faster? EDIT: This code has a flaw: Since numbers is an unordered set, there is no guarantee that numbers.pop() will remove the lowest number from the set. Nevertheless, it works (at least for me) for some input numbers: >>> sum(get_primes(2000000)) 142913828922L #That's the correct sum of all numbers below 2 million >>> 529 in get_primes(1000) False >>> 529 in get_primes(530) True EDIT: The rank so far (pure python, no external sources, all primes below 1 million): Sundaram's Sieve implementation by myself: 327ms Daniel's Sieve: 435ms Alex's recipe from Cookbok: 710ms EDIT: ~unutbu is leading the race.

    Read the article

  • To find first N prime numbers in python

    - by Rahul Tripathi
    Hi All, I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime numbers to print out. I have written this code but it doesn't throw the desired output. Instead it prints the prime numbers till the Nth number. For eg.: User enters the value of N = 7. Desired output: 2, 3, 5, 7, 11, 13, 19 Actual output: 2, 3, 5, 7 Kindly advise. i=1 x = int(input("Enter the number:")) for k in range (1, (x+1), 1): c=0 for j in range (1, (i+1), 1): a = i%j if (a==0): c = c+1 if (c==2): print (i) else: k = k-1 i=i+1

    Read the article

  • Actionscrips/Flex4: Display cut-off datapoints differently in LineChart

    - by Limited Atonement
    Dear Sirs, The issue arises when the user selects a range on the linechart that cuts off datapoints. When this happens, I would like the chart to tell the user somehow that there are data points three, just outside the range, perhaps by drawing a straight line across the top or bottom of the graph. How can I get Flex to do this for met? Let me know if you understand the question, or if you need more information, and of course, let me know the answer! Thanks! Sincerely, Aaron

    Read the article

  • Help understanding how to make a bar chart using ggplot2

    - by celenius
    I'm trying to use the bar_geom function of ggplot2, but I can't understand how to use it. I've made a small sample of my code to show what I am trying to do: library(ggplot2) # sample data sampleData = data.frame( v1=c('a','b','c','d','e', 'f','g', 'h', 'i','j'), v2=c(1:10) ) sampleData$Names = data.frame( Names = paste(sampleData$v1, sampleData$v2, sep="") ) sampleData$Values = c(1:10) # make plot x = sampleData$Values y = sampleData$Names qplot( x, y, data = sampleData, geom="bar" ) I want sampleData$Names to be on the x-axis of my graph, labeling each bar and and sampleData$Values to scale the bar height. I want the y-axis to be specified as a range. I realize that I don't understand how ggplot2 functions as this small example does not work, yet my other example is generating a plot but I cannot specify a y-range as it considers the variables to be categorical.

    Read the article

  • Select count() max() Date

    - by DAVID
    I have a table with shifts history along with emp ids. I'm using this query to retrieve a list of employees and their total shifts by specifying the range to count from: SELECT ope_id, count(ope_id) FROM operator_shift WHERE ope_shift_date >=to_date( '01-MAR-10','dd-mon-yy') and ope_shift_date <= to_date('31-MAR-10','dd-mon-yy') GROUP BY OPE_ID which gives OPE_ID COUNT(OPE_ID) 1 14 2 7 3 6 4 6 5 2 6 5 7 2 8 1 9 2 10 4 10 rows selected. How do I choose the employee with the highest number of shifts under the specified range date?

    Read the article

  • Convert varchar to numeric in Informix

    - by user302705
    Hi All I have problem while converting varchar type to Int type in Informix. Actually I dont know if the value is really varchar or not which I want to convert to INT. Its a sandbox system. As Example: I am trying to run this kind of Select telnumber from numbers n where Cast(n.telnumber AS INT) between 1234 and 9999 I got this error: "Character to numeric conversion error" If I run this query like this: Select telnumber from numbers n where n.telnumber between '1234' and '9999' it brings a resultset but not in the range that I defined. 130987 130710 130723 How can I convert telnumber to a numeric value and use it in "between" 1234 and 9999 range Thanks in advance.

    Read the article

  • A python random function acts differently when assigned to a list or called directly...

    - by Dror Hilman
    I have a python function that randomize a dictionary representing a position specific scoring matrix. for example: mat = { 'A' : [ 0.53, 0.66, 0.67, 0.05, 0.01, 0.86, 0.03, 0.97, 0.33, 0.41, 0.26 ] 'C' : [ 0.14, 0.04, 0.13, 0.92, 0.99, 0.04, 0.94, 0.00, 0.07, 0.23, 0.35 ] 'T' : [ 0.25, 0.07, 0.01, 0.01, 0.00, 0.04, 0.00, 0.03, 0.06, 0.12, 0.14 ] 'G' : [ 0.08, 0.23, 0.20, 0.02, 0.00, 0.06, 0.04, 0.00, 0.54, 0.24, 0.25 ] } The scambling function: def scramble_matrix(matrix, iterations): mat_len = len(matrix["A"]) pos1 = pos2 = 0 for count in range(iterations): pos1,pos2 = random.sample(range(mat_len), 2) #suffle the matrix: for nuc in matrix.keys(): matrix[nuc][pos1],matrix[nuc][pos2] = matrix[nuc][pos2],matrix[nuc][pos1] return matrix def print_matrix(matrix): for nuc in matrix.keys(): print nuc+"[", for count in matrix[nuc]: print "%.2f"%count, print "]" now to the problem... When I try to scramble a matrix directly, It's works fine: print_matrix(mat) print "" print_matrix(scramble_matrix(mat,10)) gives: A[ 0.53 0.66 0.67 0.05 0.01 0.86 0.03 0.97 0.33 0.41 0.26 ] C[ 0.14 0.04 0.13 0.92 0.99 0.04 0.94 0.00 0.07 0.23 0.35 ] T[ 0.25 0.07 0.01 0.01 0.00 0.04 0.00 0.03 0.06 0.12 0.14 ] G[ 0.08 0.23 0.20 0.02 0.00 0.06 0.04 0.00 0.54 0.24 0.25 ] A[ 0.41 0.97 0.03 0.86 0.53 0.66 0.33.05 0.67 0.26 0.01 ] C[ 0.23 0.00 0.94 0.04 0.14 0.04 0.07 0.92 0.13 0.35 0.99 ] T[ 0.12 0.03 0.00 0.04 0.25 0.07 0.06 0.01 0.01 0.14 0.00 ] G[ 0.24 0.00 0.04 0.06 0.08 0.23 0.54 0.02 0.20 0.25 0.00 ] but when I try to assign this scrambling to a list , it does not work!!! ... print_matrix(mat) s=[] for x in range(3): s.append(scramble_matrix(mat,10)) for matrix in s: print "" print_matrix(matrix) result: A[ 0.53 0.66 0.67 0.05 0.01 0.86 0.03 0.97 0.33 0.41 0.26 ] C[ 0.14 0.04 0.13 0.92 0.99 0.04 0.94 0.00 0.07 0.23 0.35 ] T[ 0.25 0.07 0.01 0.01 0.00 0.04 0.00 0.03 0.06 0.12 0.14 ] G[ 0.08 0.23 0.20 0.02 0.00 0.06 0.04 0.00 0.54 0.24 0.25 ] A[ 0.01 0.66 0.97 0.67 0.03 0.05 0.33 0.53 0.26 0.41 0.86 ] C[ 0.99 0.04 0.00 0.13 0.94 0.92 0.07 0.14 0.35 0.23 0.04 ] T[ 0.00 0.07 0.03 0.01 0.00 0.01 0.06 0.25 0.14 0.12 0.04 ] G[ 0.00 0.23 0.00 0.20 0.04 0.02 0.54 0.08 0.25 0.24 0.06 ] A[ 0.01 0.66 0.97 0.67 0.03 0.05 0.33 0.53 0.26 0.41 0.86 ] C[ 0.99 0.04 0.00 0.13 0.94 0.92 0.07 0.14 0.35 0.23 0.04 ] T[ 0.00 0.07 0.03 0.01 0.00 0.01 0.06 0.25 0.14 0.12 0.04 ] G[ 0.00 0.23 0.00 0.20 0.04 0.02 0.54 0.08 0.25 0.24 0.06 ] A[ 0.01 0.66 0.97 0.67 0.03 0.05 0.33 0.53 0.26 0.41 0.86 ] C[ 0.99 0.04 0.00 0.13 0.94 0.92 0.07 0.14 0.35 0.23 0.04 ] T[ 0.00 0.07 0.03 0.01 0.00 0.01 0.06 0.25 0.14 0.12 0.04 ] G[ 0.00 0.23 0.00 0.20 0.04 0.02 0.54 0.08 0.25 0.24 0.06 ] What is the problem??? Why the scrambling do not work after the first time, and all the list filled with the same matrix?!

    Read the article

  • Select Statement to show missing records (Easy Question)

    - by Gerhard Weiss
    I need some T-SQL that will show missing records. Here is some sample data: Emp 1 01/01/2010 02/01/2010 04/01/2010 06/01/2010 Emp 2 02/01/2010 04/01/2010 05/01/2010 etc... I need to know Emp 1 is missing 03/01/2010 05/01/2010 Emp 2 is missing 01/01/2010 03/01/2010 06/01/2010 The range to check will start with todays date and go back 6 months. In this example, lets say today's date is 06/12/2010 so the range is going to be 01/01/2010 thru 06/01/2010. The day is always going to be the 1st in the data. Thanks a bunch. :) Gerhard Weiss Secretary of Great Lakes Area .NET Users Group GANG Upcoming Meetings | GANG LinkedIn Group

    Read the article

  • How to store javascript variables in iPhone application

    - by sugar
    <script type="text/javascript"> function getSelectionRange() { var sel; if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount) { return sel.getRangeAt(0); } } else if (document.selection) { return document.selection.createRange(); } return null; } var range; </script> whatShouldBeHere=[wvText stringByEvaluatingJavaScriptFromString:@"getSelectionRange();"]; Here, method getSelectionRange is returning JavaScript Object of Range type. How can I catch & store in plist file in iPhone application ? Thanks in advance for sharing your knowledge. Sagar

    Read the article

  • More specific NSNumberFormatter failure behaviour

    - by Volte
    I have an NSTextField into which I need the user to enter a number between a max and min, and it would be nice if I could detect when the NSNumberFormatter fails that particular test so I can either display a nicer message ("The number is too large" is not very helpful, it needs to display the valid range) or simply set the field automatically to the nearest valid value. I've looked at the NSTextField delegate's -control:didFailToFormatString:errorDescription: method which doesn't seem to allow you to modify the error, and I've looked at overriding the NSNumberFormatter's -getObjectValue:forString:range:error: method which does give me an NSError that I can modify, but there doesn't seem to be any way to determine which specific error was returned. Since I am just entering a simple integer, I don't need most of the functionality in NSNumberFormatter, would I be better off just writing my own formatter from scratch?

    Read the article

  • How to counter the "one true language" perspective?

    - by Rob Wells
    How do you work with someone when they haven't been able to see that there is a range of other languages out there beyond "The One True Path"? I mean someone who hasn't realised that the modern software professional has a range of tools in his toolbox. The person whose knee jerk reaction is, for example, "We must do this is C++!" "Everything must be done in C++!" What's the best approach to open people up to the fact that "not everything is a nail"? How may I introduce them to having a well-equipped toolbox, selecting the best tool for the job at hand?

    Read the article

  • svn reintegrate a branch with externals fails

    - by dnndeveloper
    using svn 1.6.6 with tortoisesvn 1.6.6 what I am doing: 1) Apply external properties to a folder in the trunk (both single file and folder external, externals are binary files) 2) Create a branch from the trunk and update the entire project 3) Modify a file on the branch and commit the changes, then update the entire project. 4) Merge - "Reintegrate a branch" when I get to the last screen I click "test merge" and get this error: Error: Cannot reintegrate into mixed-revision working copy; try updating first I update the entire project and still the same error. other observations: If I "Merge a range of revisions" everything works fine. If I remove the externals everything works fine using either "Merge a range of revisions" or "Reintegrate a branch" Anyone else having this issue?

    Read the article

  • Why does my Excel add-in only half work?

    - by Dan Crowther
    I've created an Excel add-in using Visual Studio 2008. It has a ribbon, a bunch of panes and code that adds sheets and ranges and gets information scraped from a web page. When I run it on my dev PC it works perfectly. I used the Publish command to publich it and installed on a Windows XP virtual PC. The installation seemed fine and when I open Excel I see my ribbon. If I click a button that shows a pane, up pops the pane. If I enter some details into the pane that should create a range and populate it with data from a web page, the range is created but the web page is not visited (I have tested that I have connectivity). One of my buttons adds a hidden worksheet and another displays or hides that sheet. One of these buttons is not working. I've tried everything I can think of. I'm wondering if there are any permissions or trust issues I need to deal with?

    Read the article

  • Too many values problem

    - by DraskyVanderhoff
    Hi , i was trying to make a full lot of ips for testing using this code : ip_is = [i for i in range(256)] ports = [i for i in range(1024,49152)] return [str(i1)+"."+str(i2)+"."+str(i3)+"."+str(i4)+":"+str(p) for i1,i2,i3,i4,port in ip_is,ip_is,ip_is,ip_is,ports] The problem is the 3rd line in which is made the ip list. If there is a way to make it all at once or how can make one at time in a lazy way ? I'm pretty noob at python :P. Thanks for the Help :)

    Read the article

  • Computationally simple Pseudo-Gaussian Distribution with varying mean and standard deviation?

    - by mstksg
    This picture from wikipedia has a nice example of the sort of functions I'd ideally like to generate http://en.wikipedia.org/wiki/File:Normal_Distribution_PDF.svg Right now I'm using the Irwin-Hall Distribution, which is more or less a Polynomial approximation of the Gaussian distribution...basically, you use uniform random number generator and iterate it x times, and take the average. The more iterations, the more like a Gaussian Distribution it is. It's pretty nice; however I'd like to be able to have one where I can vary the mean. For example, let's say I wanted a number between the range 0 and 10, but around 7. Like, the mean (if I repeated this function multiple times) would turn out to be 7, but the actual range is 0-10. Is there one I should look up, or should I work on doing some fancy maths with standard Gaussian Distributions?

    Read the article

  • Writing file from HttpWebRequest periodically vs. after download finishes?

    - by WB3000
    Right now I am using this code to download files (with a Range header). Most of the files are large, and it is running 99% of CPU currently as the file downloads. Is there any way that the file can be written periodically so that it does not remain in RAM constantly? private byte[] GetWebPageContent(string url, long start, long finish) { byte[] result = new byte[finish]; HttpWebRequest request; request = WebRequest.Create(url) as HttpWebRequest; //request.Headers.Add("Range", "bytes=" + start + "-" + finish); request.AddRange((int)start, (int)finish); using (WebResponse response = request.GetResponse()) { return ReadFully(response.GetResponseStream()); } } public static byte[] ReadFully(Stream stream) { byte[] buffer = new byte[32768]; using (MemoryStream ms = new MemoryStream()) { while (true) { int read = stream.Read(buffer, 0, buffer.Length); if (read <= 0) return ms.ToArray(); ms.Write(buffer, 0, read); } } }

    Read the article

  • Need to make sure value is within 0-255

    - by igor
    This is probably really easy, but I'm lost on how to "make sure" it is in this range.. So basically we have class Color and many functions to implement from it. this function I need is: Effects: corrects a color value to be within 0-255 inclusive. If value is outside this range, adjusts to either 0 or 255, whichever is closer. This is what I have so far: static int correctValue(int value) { if(value<0) value=0; if(value>255) value=255; } Sorry for such a simple question ;/

    Read the article

  • pasteHTML removes markup

    - by ullmark
    I am writing a plugin to an old IE-only WYSIWYG-editor which resides in an old CMS. I've created a plugin that opens an popup where the user kan enter the url of an youtube clip. The popup then creates the corrent <object..><param..> markup for the embed and uses Internet Explorers pasteHTML function; var range = plugin.editorDocument.selection.createRange(); var embedHtml = OpenDialog(dialogUrl, null, 400, 200); if (!embedHtml) { return; } range.pasteHTML(embedHtml); I know it's missing a bit of information about some of the variables but you get the picture. The problem is that the <param>-tags gets removed when i run the pasteHTML. I wonder if anyone have an idea of fixing this, and letting me keep my param-tags

    Read the article

  • Dual slider control with custom skin

    - by Ryan French
    Hi All, I'm currently trying to create a page for users to select two points from a range, using a slide control. The first point in the range is when an alert will be sent to the user, the second point is a max limit. What I would like to do is have the bar colored green from the 0 point to the first slider point, then orange between the two sliders, and lastly red from the second slider up to the other end of the bar. Does anyone know of an easy was I can do this or of a slider control that can be skinned to do this?

    Read the article

< Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >