Search Results

Search found 35 results on 2 pages for 'radix'.

Page 1/2 | 1 2  | Next Page >

  • Radix Sort in Python [on hold]

    - by Steven Ramsey
    I could use some help. How would you write a program in python that implements a radix sort? Here is some info: A radix sort for base 10 integers is a based on sorting punch cards, but it turns out the sort is very ecient. The sort utilizes a main bin and 10 digit bins. Each bin acts like a queue and maintains its values in the order they arrive. The algorithm begins by placing each number in the main bin. Then it considers the ones digit for each value. The rst value is removed and placed in the digit bin corresponding to the ones digit. For example, 534 is placed in digit bin 4 and 662 is placed in the digit bin 2. Once all the values in the main bin are placed in the corresponding digit bin for ones, the values are collected from bin 0 to bin 9 (in that order) and placed back in the main bin. The process continues with the tens digit, the hundreds, and so on. After the last digit is processed, the main bin contains the values in order. Use randint, found in random, to create random integers from 1 to 100000. Use a list comphrension to create a list of varying sizes (10, 100, 1000, 10000, etc.). To use indexing to access the digits rst convert the integer to a string. For this sort to work, all numbers must have the same number of digits. To zero pad integers with leading zeros, use the string method str.zfill(). Once main bin is sorted, convert the strings back to integers. I'm not sure how to start this, Any help is appreciated. Thank you.

    Read the article

  • Radix sort in java help

    - by endif
    Hi i need some help to improve my code. I am trying to use Radixsort to sort array of 10 numbers (for example) in increasing order. When i run the program with array of size 10 and put 10 random int numbers in like 70 309 450 279 799 192 586 609 54 657 i get this out: 450 309 192 279 54 192 586 657 54 609 Don´t see where my error is in the code. class IntQueue { static class Hlekkur { int tala; Hlekkur naest; } Hlekkur fyrsti; Hlekkur sidasti; int n; public IntQueue() { fyrsti = sidasti = null; } // First number in queue. public int first() { return fyrsti.tala; } public int get() { int res = fyrsti.tala; n--; if( fyrsti == sidasti ) fyrsti = sidasti = null; else fyrsti = fyrsti.naest; return res; } public void put( int i ) { Hlekkur nyr = new Hlekkur(); n++; nyr.tala = i; if( sidasti==null ) f yrsti = sidasti = nyr; else { sidasti.naest = nyr; sidasti = nyr; } } public int count() { return n; } public static void radixSort(int [] q, int n, int d){ IntQueue [] queue = new IntQueue[n]; for (int k = 0; k < n; k++){ queue[k] = new IntQueue(); } for (int i = d-1; i >=0; i--){ for (int j = 0; j < n; j++){ while(queue[j].count() != 0) { queue[j].get(); } } for (int index = 0; index < n; index++){ // trying to look at one of three digit to sort after. int v=1; int digit = (q[index]/v)%10; v*=10; queue[digit].put(q[index]); } for (int p = 0; p < n; p++){ while(queue[p].count() != 0) { q[p] = (queue[p].get()); } } } } } I am also thinking can I let the function take one queue as an argument and on return that queue is in increasing order? If so how? Please help. Sorry if my english is bad not so good in it. Please let know if you need more details. import java.util.Random; public class RadTest extends IntQueue { public static void main(String[] args) { int [] q = new int[10]; Random r = new Random(); int t = 0; int size = 10; while(t != size) { q[t] = (r.nextInt(1000)); t++; } for(int i = 0; i!= size; i++) { System.out.println(q[i]); } System.out.println("Radad: \n"); radixSort(q,size,3); for(int i = 0; i!= size; i++) { System.out.println(q[i]); } } } Hope this is what you were talking about...

    Read the article

  • Who does non-decimal bignums with floating radix point?

    - by boost
    Nice as the Tcl libraries math::bignum and math::bigfloat are, the middle ground between the two needs to be addressed. Namely, bignums which are in different radices and have a radix point. At present math::bignum only handles integers (afaict) and math::bigfloat won't let you specify different radices to math::bigfloat::fromstr (ditto). Does anyone know of a library, for any of the major scripting languages (e.g. Tcl, Perl, Python, Ruby, Lua) or less major ones (newLISP for example), which implements bignums in different radices with handling for radix point?

    Read the article

  • I am getting a Radix out of range exception on performing decryption

    - by user3672391
    I am generating a keypair and converting one of the same into string which later is inserted into the database using the following code: KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2048); KeyPair generatedKeyPair = keyGen.genKeyPair(); PublicKey pubkey = generatedKeyPair.getPublic(); PrivateKey prvkey = generatedKeyPair.getPrivate(); System.out.println("My Public Key>>>>>>>>>>>"+pubkey); System.out.println("My Private Key>>>>>>>>>>>"+prvkey); String keyAsString = new BigInteger(prvkey.getEncoded()).toString(64); I then retrieve the string from the database and convert it back to the original key using the following code (where rst is my ResultSet): String keyAsString = rst.getString("privateKey").toString(); byte[] bytes = new BigInteger(keyAsString, 64).toByteArray(); //byte k[] = "HignDlPs".getBytes(); PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(bytes); KeyFactory rsaKeyFac = KeyFactory.getInstance("RSA"); PrivateKey privKey = rsaKeyFac.generatePrivate(encodedKeySpec); On using the privKey for RSA decryption, I get the following exception java.lang.NumberFormatException: Radix out of range at java.math.BigInteger.<init>(BigInteger.java:294) at com.util.SimpleFTPClient.downloadFile(SimpleFTPClient.java:176) at com.Action.FileDownload.processRequest(FileDownload.java:64) at com.Action.FileDownload.doGet(FileDownload.java:94) Please guide.

    Read the article

  • question about LSD radix sort

    - by davit-datuashvili
    hello i have following code public class LSD{ public static int R=1<<8; public static int bytesword=4; public static void radixLSD(int a[],int l,int r){ int aux[]=new int[a.length]; for (int d=bytesword-1;d>=0;d--){ int i, j; int count[]=new int[R+1]; for ( j=0;j<R;j++) count[j]=0; for (i=l;i<=r;i++) count[digit(a[i],d)+1]++; for (j=1;j<R;j++) count[j]+=count[j-1]; for (i=l;i<=r;i++) aux[count[digit(a[i],d)]++]=a[i]; for (i=l;i<=r;i++) a[i]=aux[i-1]; } } public static void main(String[]args){ int a[]=new int[]{3,6,5,7,4,8,9}; radixLSD(a,0,a.length-1); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } public static int digit(int n,int d){ return (n>>d)&1; } } but it show me mistake java.lang.ArrayIndexOutOfBoundsException: -1 at LSD.radixLSD(LSD.java:19) at LSD.main(LSD.java:29) please help me

    Read the article

  • Implementing a Patricia Trie for use as a dictionary

    - by Regis Frey
    I'm attempting to implement a Patricia Trie with the methods addWord(), isWord(), and isPrefix() as a means to store a large dictionary of words for quick retrieval (including prefix search). I've read up on the concepts but they just aren't clarifying into an implementation. I want to know (in Java or Python code) how to implement the Trie, particularly the nodes (or should I implement it recursively). I saw one person who implemented it with an array of 26 child nodes set to null/None. Is there a better strategy (such as treating the letters as bits) and how would you implement it?

    Read the article

  • convert integer to a string in a given numeric base in python

    - by Mark Borgerding
    Python allows easy creation of an integer from a string of a given base via int(str,base). I want to perform the inverse: creation of a string from an integer. i.e. I want some function int2base(num,base) such that: int( int2base( X , BASE ) , BASE ) == X the function name/argument order is unimportant For any number X and base BASE that int() will accept. This is an easy function to write -- in fact easier than describing it in this question -- however, I feel like I must be missing something. I know about the functions bin,oct,hex; but I cannot use them for a few reasons: Those functions are not available on older versions of python with which I need compatibility (2.2) I want a general solution that can be called the same way for different bases I want to allow bases other than 2,8,16 Related Python elegant inverse function of int(string,base) Interger to base-x system using recursion in python Base 62 conversion in Python How to convert an integer to the shortest url-safe string in Python?

    Read the article

  • Hi, i want to implement a small routing table for my learning? I know it is implemented using radix/

    - by aks
    Hi, i want to implement a small routing table for my learning? I know it is implemented using radix/patricia tree in routers? Can someone give me an idea on how to go about implementing the same? The major issue i feel is storing IP ADDRESS. For example : 10.1.1.0 network next hop 20.1.1.1 10.1.0.0 network next hop 40.1.1.1 Can someone give me a declaration of the struct from which i can have an idea?

    Read the article

  • Are there any radix/patricia/critbit trees for Python?

    - by Andrew Dalke
    I have about 10,000 words used as a set of inverted indices to about 500,000 documents. Both are normalized so the index is a mapping of integers (word id) to a set of integers (ids of documents which contain the word). My prototype uses Python's set as the obvious data type. When I do a search for a document I find the list of N search words and their corresponding N sets. I want to return the set of documents in the intersection of those N sets. Python's "intersect" method is implemented as a pairwise reduction. I think I can do better with a parallel search of sorted sets, so long as the library offers a fast way to get the next entry after i. I've been looking for something like that for some time. Years ago I wrote PyJudy but I no longer maintain it and I know how much work it would take to get it to a stage where I'm comfortable with it again. I would rather use someone else's well-tested code, and I would like one which supports fast serialization/deserialization. I can't find any, or at least not any with Python bindings. There is avltree which does what I want, but since even the pair-wise set merge take longer than I want, I suspect I want to have all my operations done in C/C++. Do you know of any radix/patricia/critbit tree libraries written as C/C++ extensions for Python? Failing that, what is the most appropriate library which I should wrap? The Judy Array site hasn't been updated in 6 years, with 1.0.5 released in May 2007. (Although it does build cleanly so perhaps It Just Works.)

    Read the article

  • How to take a screen shot in iPhone via code

    - by Radix
    Hello friends; I am working on an app and am almost done with it, but the only thing pending is that i am not able to take screen shots of my screen on the touch of the UIButton object. I have saw a code available which said to use UIGetScreenImage(), but alas that didn't worked fine. I want to take the screen shot and display it in the UIImageView. So can you please provide me with the link or code to do the same, that would be really nice of you Thanks & Regards Radix

    Read the article

  • How to check Internet status in iPhone

    - by Radix
    Hello; I wanted to check whether internet is connected or not using either the SystemConfiguration or the CFNetwork i am not quite sure which one. Then i want to know that if the internet is connected then is it connected through wifi or not. I tried an example where i used the below code -(IBAction) shownetworkStatus { NSURL *url = [NSURL URLWithString:@"www.google.com"]; if (url!=NULL) { lbl.text = @"Connected"; } else { lbl.text = @"notConnected"; } } some say that its not valid as per apple and you have to use the SystemConfiguration Framework, Please let me know what needs to be done. Also i personally think that what i am doing in the above code is not proper as if one day google may also be down due to maintenance or some other factors. Also if you could provide me a link where i could display the name of the WIFI network then it would be really cool. I searched the internet then i got these Reachability.h code which again is a bouncer as i wana learn the concepts not copy paste them Thanks and Regards Radix

    Read the article

  • Workstations cannot see new MS Server 2008 domain, but can access DHCP.

    - by Radix
    The XP Pro workstations do not see the new replacement domain upon boot; they only see their cached entry for the old (server 2003) domain controller. The old_server is not connected to the network. I have DHCP working with the same scope as the old_server. In my "before-asking" search for a solution I came across the following two articles, and I recall doing things as suggested by the articles. http://www.windowsreference.com/windows-server-2008/how-to-setup-dhcp-server-in-windows-server-2008-step-by-step-guide/ http://www.windowsreference.com/windows-server-2008/step-by-step-guide-for-windows-server-2008-domain-controller-and-dns-server-setup/ The only possible issue is: I was under the impression that the domain netbios needed to match the DC's netbios. The DC netbios is city01 while the domain's FQDN is city.domain.org (I think this is mistaken and should have been just domain.org) But, the second link led me to a post which I believe answers my question. I did as they instructed by opening Local Area Connection Properties, then selecting TCP/IPv4 and setting the sole preferred DNS server to the local hosts static IP (10.10.1.1). Search for "Your problems should clear up" for the post I'm referencing: http://forums.techarena.in/active-directory/1032797.htm Have I misunderstood their instructions? I am hoping to reach the point where I can define users and user groups. Also, does TechNet have a single theoretical overview document I could read. I really don't like treating comps as magic. I will be watching this closely and will quickly answer any questions. If I've left anything out it is because I did not know it was needed. PS: I am loath to ask obviously basic questions, but I am tired and wish to fix this before tomorrow. Also, this is my first server installation, thank you for your help.

    Read the article

  • Workstations cannot see new MS Server 2008 domain, but can access DHCP. (solved)

    - by Radix
    The XP Pro workstations do not see the new replacement domain upon boot; they only see their cached entry for the old (server 2003) domain controller. The old_server is not connected to the network. I have DHCP working with the same scope as the old_server. In my "before-asking" search for a solution I came across the following two articles, and I recall doing things as suggested by the articles. http://www.windowsreference.com/windows-server-2008/how-to-setup-dhcp-server-in-windows-server-2008-step-by-step-guide/ http://www.windowsreference.com/windows-server-2008/step-by-step-guide-for-windows-server-2008-domain-controller-and-dns-server-setup/ The only possible issue is: I was under the impression that the domain netbios needed to match the DC's netbios. The DC netbios is city01 while the domain's FQDN is city.domain.org (I think this is mistaken and should have been just domain.org) But, the second link led me to a post which I believe answers my question. I did as they instructed by opening Local Area Connection Properties, then selecting TCP/IPv4 and setting the sole preferred DNS server to the local hosts static IP (10.10.1.1). Search for "Your problems should clear up" for the post I'm referencing: http://forums.techarena.in/active-directory/1032797.htm Have I misunderstood their instructions? I am hoping to reach the point where I can define users and user groups. Also, does TechNet have a single theoretical overview document I could read. I really don't like treating comps as magic. I will be watching this closely and will quickly answer any questions. If I've left anything out it is because I did not know it was needed. PS: I am loath to ask obviously basic questions, but I am tired and wish to fix this before tomorrow. Also, this is my first server installation, thank you for your help.

    Read the article

  • How do you create virtual folders from saved search

    - by Jérôme Radix
    I would like to have on unix-like platforms, the same functionality as to Windows 7 Library folders (aka virtual folders) you see in Windows Explorer. Gnome Nautilus do that kind of virtual folders through saved search. But I want a system-wide solution, not a gnome-wide solution. Is there a tool that creates virtual folders from the concatenation of multiple search queries (the result of multiple find commands ?). The solution should index files for better performances and you should be able to define the default folder for copy operations. I assume the solution of this kind of problem certainly use FUSE, but I can't see a complete solution to this kind of task in FUSE applications.

    Read the article

  • How do you create virtual folders from saved search

    - by Jérôme Radix
    I would like to have on unix-like platforms, the same functionality as to Windows 7 Library folders (aka virtual folders) you see in Windows Explorer. Gnome Nautilus do that kind of virtual folders through saved search. But I want a system-wide solution, not a gnome-wide solution. Is there a tool that creates virtual folders from the concatenation of multiple search queries (the result of multiple find commands ?). The solution should index files for better performances and you should be able to define the default folder for copy operations. I assume the solution of this kind of problem certainly use FUSE, but I can't see a complete solution to this kind of task in FUSE applications.

    Read the article

  • A question in java.lang.Integer internal code

    - by Daziplqa
    Hi folks, While looking in the code of the method: Integer.toHexString I found the following code : public static String toHexString(int i) { return toUnsignedString(i, 4); } private static String toUnsignedString(int i, int shift) { char[] buf = new char[32]; int charPos = 32; int radix = 1 << shift; int mask = radix - 1; do { buf[--charPos] = digits[i & mask]; i >>>= shift; } while (i != 0); return new String(buf, charPos, (32 - charPos)); } The question is, in toUnsignedString, why we create a char arr of 32 chars?

    Read the article

  • twitter api is throwing exception "# is not a valid value for Int32" while getting freinds

    - by vakas
    i am using the api twitterizer.framework while getting the friends of a user the api starts throwing this error. "# is not a valid value for Int32. --- System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex at System.ParseNumbers.StringToInt(String s, Int32 radix, Int32 flags, Int32* currPos) at System.Convert.ToInt32(String value, Int32 fromBase) at System.ComponentModel.Int32Converter.FromString(String value, Int32 radix) at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) --- End of inner exception stack trace --- at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) at System.ComponentModel.TypeConverter.ConvertFromString(ITypeDescriptorContext context, CultureInfo culture, String text) at System.Drawing.ColorConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) at System.ComponentModel.TypeConverter.ConvertFromString(String text) at System.Drawing.ColorTranslator.FromHtml(String htmlColor) at Twitterizer.Framework.TwitterRequest.ParseUserNode(XmlNode element) in C:\Projects\twitterizer\Twiterizer.Framework\TwitterRequest.cs:line 514 at Twitterizer.Framework.TwitterRequest.ParseUsers(XmlElement element) in C:\Projects\twitterizer\Twiterizer.Framework\TwitterRequest.cs:line 483 at Twitterizer.Framework.TwitterRequest.ParseResponseData(TwitterRequestData data) in C:\Projects\twitterizer\Twiterizer.Framework\TwitterRequest.cs:line 305" how to handle this?

    Read the article

  • Rails: link_to_remote prototype helper with :with option

    - by Syed Aslam
    I am trying to grab the current value of a drop down list with Prototype and passing it along using :with like this <%= link_to_remote "today", :update => "choices", :url => { :action => "check_availability" } , :with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'", :loading => "spinner.show(); $('submit').disable();", :complete => "spinner.hide(); $('submit').enable();" %> However, this is not working as expected. I am unable to access parameters in the controller as the link_to_remote helper is sending parameters like this: Parameters: {"succ"=>"function () {\n return this + 1;\n}", "action"=>"check_availability", "round"=>"function () {\n return __method.apply(null, [this].concat($A(arguments)));\n}", "ceil"=>"function () {\n return __method.apply(null, [this].concat($A(arguments)));\n}", "floor"=>"function () {\n return __method.apply(null, [this].concat($A(arguments)));\n}", "times"=>"function (iterator, context) {\n $R(0, this, true).each(iterator, context);\n return this;\n}", "toPaddedString"=>"function (length, radix) {\n var string = this.toString(radix || 10);\n return \"0\".times(length - string.length) + string;\n}", "toColorPart"=>"function () {\n return this.toPaddedString(2, 16);\n}", "abs"=>"function () {\n return __method.apply(null, [this].concat($A(arguments)));\n}", "controller"=>"main"} Where am I going wrong? Is there a better way to do this?

    Read the article

  • substitution cypher with different alphabet length

    - by seanizer
    I would like to implement a simple substitution cypher to mask private ids in URLs I know how my IDs will look like (combination of upperchase ascii, digits and underscore), and they will be rather long, as they are composed keys. I would like to use a longer alphabet to shorten the resulting codes (I'd like to use upper and lower case ascii letters, digits and nothing else). So my incoming alphabet would be [A-Z0-9_] (37 chars) and my outgoing alphabet would be [A-Za-z0-9] (62 chars) so a compression of almost 50% would be available. let's say my URLs look like this: /my/page/GFZHFFFZFZTFZTF_24_F34 and I want them to look like this instead: /my/page/Ft32zfegZFV5 Obviously both arrays would be shuffled to bring some random order in. This does not have to be secure. if someone figures it out: fine, but I don't want the scheme to be obvious. My desired solution would be to convert the string to an integer representation of radix 37, convert the radix to 62 and use the second alphabet to write out that number. is there any sample code available that does something similar? Integer.parseInt ( http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt%28java.lang.String,%20int%29 ) has some similar logic, but it is hard-coded to use standard digit behavior Any hints? I am using java to implement this but code or pseudo-code in any other language is of course also helpful

    Read the article

  • Fast file search algorithm for IP addresses

    - by Dave Jarvis
    Question What is the fastest way to find if an IP address exists in a file that contains IP addresses sorted as: 219.93.88.62 219.94.181.87 219.94.193.96 220.1.72.201 220.110.162.50 220.126.52.187 220.126.52.247 Constraints No database (e.g., MySQL, PostgreSQL, Oracle, etc.). Infrequent pre-processing is allowed (see possibilities section) Would be nice not to have to load the file each query (131Kb) Uses under 5 megabytes of disk space File Details One IP address per line 9500+ lines Possible Solutions Create a directory hierarchy (radix tree?) then use is_dir() (sadly, this uses 87 megabytes)

    Read the article

  • C variable declarations after function heading in definition

    - by Yktula
    When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations that followed the "function heading" in the definition. Is this valid in ISO C (C99)? when should this be done in production code instead of just declaring the variables within the "function heading?" Why is it being done here? I refer to the function heading the string that looks like this: int someFunction(int i, int b) {

    Read the article

  • need help with parseInt

    - by cmona
    hello, how can i get for example the integer codeInt=082 from String code='A082' i have tried this: int codeInt = Integer.parseInt(code.substring(1,4)); and i get codeInt=82 ,it leaves the first 0 but i want the full code '082'. i thought of parseInt(String s, int radix) but i don't know how . any help will be appreciated . thanks.

    Read the article

1 2  | Next Page >