How do I check if a number is a palindrome?
Any language. Any algorithm (except making the number a string and then reversing the string). Also, I actually have to do this, and I'll be posting my solution too. ...
Any language. Any algorithm (except making the number a string and then reversing the string). Also, I actually have to do this, and I'll be posting my solution too. ...
I'm writing a lightweight XML editor, and in cases where the user's input is not well formed, I would like to indicate to the user where the problem is, or at least where the first problem is. Does anyone know of an existing algorithm for this? If looking at code helps, if I could fill in the FindIndexOfInvalidXml method (or something ...
Recently, someone asked about an algorithm for reversing a string in place in C. Most of the proposed solutions had troubles when dealing with non single-byte strings. So, I was wondering what could be a good algorithm for dealing specifically with utf-8 strings. I came up with some code, which I'm posting as an answer, but I'd be glad ...
I am trying to help someone write a program that I thought would be easy, but of course it never is :) I am trying to take a class roster (usually between 10-20 students) and effectivly uniquely pair off each classmate to another to make unique groups. Therefore in a class of 10 people, you can have 9 groups. It needs to be able to han...
What is meant by "Constant Amortized Time" when talking about time complexity of an algorithm? ...
I always wondered what different methods Google Desktop Search is using so that it uses least CPU and memory while indexing a computer containing more 100,000 files on an average. In just few hours it has indexed the whole system and I did not see it eating up my CPU, memory etc. If any of you have done some research, please do share. ...
How do I split strings in J2ME in an effective way? There is a StringTokenizer in the standard edition, but it is absent in the micro edition. ...
I have a list of changes to a list - Adds and Deletes. The list could be huge - say 10'000 items. I want to know the state of the list after change 9'000. I could walk the list from the start all the way to change 9'000. That seems a bit long-winded to me. I could keep a list of items and record when they're added and when they're de...
I'm trying to work through Project Euler and I'm hitting a barrier on problem 03. I have an algorithm that works for smaller numbers, but problem 3 uses a very, very large number. Problem 03: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? Here is my solution in C# and it's b...
I was playing around with my own Sudoku solver and was looking for some pointers to good and fast design when I came across this: def r(a):i=a.find('0');~i or exit(a);[m in[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]for j in range(81)]or r(a[:i]+m+a[i+1:])for m in'%d'%5**18] from sys import*;r(argv[1]) My own implementation solve...
How can I find the largest increasing (non-contiguous) subset of an array? For example, if A= array(50,1,4,9,2,18,6,3,7,10) the largest increasing non-contiguous subset is either (1,4,6,7,10) or (1,2,6,7,10). I can intuitively see how to find the subset, but I don't know how to design the algorithm. thanks. ...
Hello fellow stackoverflowers! I have a word list of 200.000 string entries, average string length is around 30 characters. This list of words are the key and to each key i have a domain object. I would like to find the domain objects in this collection by only knowing a part of the key. I.E. the search string "kov" would for example ma...
How can you round any number (not just integers > 0) to N significant digits? For example, if I want to round to 3 significant digits, I'm looking for a formula that could take: 1,239,451 and return 1,240,000 12.1257 and return 12.1 .0681 and return .0681 5 and return 5 Naturally the algorithm should not be hard-coded to only handl...
I'm reading data from a device which measures distance. My sample rate is high so that I can measure large changes in distance (i.e. velocity) but this means that, when the velocity is low, the device delivers a number of measurements which are identical (due to the granularity of the device). This results in a 'stepped' curve. What I n...
Do any one know which sorting algorithm is used by .net when we implement IComparer in our class? ...
I need to implement some kind of metric space search in Postgres(*) (PL or PL/Python). So, I'm looking for good sources (or papers) with a very clear and crisp explanation of the machinery behind these ideas, in such way that I can implement it myself. I would prefer clarity over efficiency. (*) The need for that is described better he...
We are embarking on some R&D for a staff rostering system, and I know that there are some suggested algorithms such as the memetic algorithm etc., but I cannot find any additional information on the web. Does anyone know any research journals, or pseudocode out there which better explains these algorithms? Thanks, Devan ...
Hey folks, I've got a unidirectional tree of objects, in which each objects points to its parent. Given an object, I need to obtain its entire subtree of descendants, as a collection of objects. The objects are not actually in any data structure, but I can easily get a collection of all the objects. The naive approach is to examine eac...
If I have a string (010) and i want to add 1 to it (011) what value type should i use to convert this string into a number for adding and at the same time preserve the whole number and not 10 + 1 = 11. ...
We have an auto-complete list that's populated when an you send an email to someone, which is all well and good until the list gets really big you need to type more and more of an address to get to the one you want, which goes against the purpose of auto-complete I was thinking that some logic should be added so that the auto-complete r...