Given two numbers a, b such that 1 <= a , b <= 10000000000 (10^10). My problem is to check whether the digits in them are permutation of each other or not. What is the fastest way of doing it? I was thinks of using hashing but unable to find any suitable hash function. Any suggestions?
For e.g -
123 is a valid permutation of 312
A...
Hi Guys,
I've got a 1km square, I'm dividing it up into 100meters both on the positive and negative sides of it..
__________y__________
| | |
| | |
| | |
|---------|---------| x
| | |
| | |
...
Hi all,
Like most of us, I am a big fan of improving efficiency of code. So much so that I would rather choose fast-executing dirty code over something which might be more elegant or clean, but slower.
Fortunately for all of us, in most cases, the faster and more efficient solutions are also the cleaner and the most elegant ones. I u...
So I need to read flags in bits and set flags in bits. These bits are in various sizes of integer: int16, int32, int64, etc.
I would like to have a function that does something like this:
static integertype function(integertype data, char startbit, char endbit);
I don't want to code what will be the same code to isolate bits from for...
List<T> list = new ArrayList<T>();
1 method:
for(int i = list.length - 1; i >= 0; i--) {
System.out.println(list.get(i));
}
2 method:
for(T t : list) {
System.out.println(t);
}
3 method:
Iterator<T> it = list.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
...
Possible Duplicate:
Is shifting bits faster than multiplying and dividing in Java? .NET?
To double a value, is <<1 more performant than *2 in modern languages?
I'm particularly interested in Java and C#. Does having optimization turned on at compile-time change things?
...
I am currently using select() to act as a timer. I have network receive operations which occur within a loop, and every few seconds a processing operation needs to occur.
As a result, the select() statement's timeout constantly changes -- decreasing to zero over time and then restarting at 3.
rv = select(selectmonitor+1, &readnet, NULL...
Hello all. I have a script and I want to code it so that it becomes active every hour on the half hour. This is the code I have so far.
from ConfigParser import *
import emailModule
from datetime import datetime
import time
configuration = ConfigParser()
configuration.read('Email.conf')
email = emailModule.emailModule(configuration)
...
Hello,
I just spent a whole week tracking down and whacking memory leaks over the head, and I arrived on the other end of that week a little dazed. There has to be a better way to do this, is all I can think, and so I figured it was time to ask about this rather heavy subject.
This post turned out to be rather huge. Apologies for that,...
I want to add natural numbers from A to B in a set. Currently I am inserting each and every number from A to B, one by one in the set like this,
set<int> s;
for(int j=A; j<=B; j++)
s.insert(j);
But it takes O(n) time (here n = (B - A)+1). Is there any pre-defined way in STL to do it in O(1) time?
Thanks
...
In my .html.erb file, I have a lot of lines of information to display. I am accomplishing this with a simple: (using blueprint css)
<% for event in @user.events %>
<div class="span-5 border">Descriptor:</div> <div class="span-5 last"><%=h event.foo%></div><br/>
<% end %>
How can I make it so that I can call some function that would re...
In Matlab, at what point is having a sparse array better than a normal array if I still have a lot of calculations to do on it, and about 25% of the array are non-zeros?
...
Boiled down: Is it better to have the calculated field returned with the rest of the results or is it better to calculate it later when you need it?
Example:
I have a GridView that displays search results that has many fields like:
Application ID
Name
Account Type
Account Number
etc.
The account number field is not always consisten...
I am doing some fairly extensive string manipulations using regular expressions in Java. Currently, I have many blocks of code that look something like:
Matcher m = Pattern.compile("some pattern").matcher(text);
StringBuilder b = new StringBuilder();
int prevMatchIx = 0;
while (m.find()) {
b.append(text.substring(prevMatchIx, m.start()...
A while back I posted a different question regarding column order. While this question does not relate to column order, I was suggested to make my table differently from how I was making it.
Lets say I am selling 100 products. Some of these products are compatible with each other, some are not. Some have not been tested yet (I did not m...
I'm migrating from Matlab to C + GSL and I would like to know what's the most efficient way to calculate the matrix B for which:
B[i][j] = exp(A[i][j])
where i in [0, Ny] and j in [0, Nx].
Notice that this is different from matrix exponential:
B = exp(A)
which can be accomplished with some unstable/unsupported code in GSL (linalg....
Suppose I have the following object:
class Foo(object):
def __init__(self, name=None):
self.name = name
def __repr__(self):
return self.name
And a list containing multiple instances, such as:
list = [Foo(name='alice'), Foo(name='bob'), Foo(name='charlie')]
If I want to find an object with a given name, I could use the ...
I have some several codes in PHP to do jobs that MySQL could do.
such as sorting, merging each data from different MySQL tables, etc...
Lately, I found out that I can do all these stuffs with one MySQL query.
I am wondering is it better to give the MySQL capable jobs to MySQL or to PHP.
efficiencies, speed, etc..
Thank You,
...
Hi,
I have a table containing integer values from 0 to some large number N, but has some number gaps. I'm trying to write an efficient query that'll find the first set of continuous values of some length that are within 0 and N but are not contained in the said table. This has applications to find unused ids, etc.
For example, given th...
I'm writing a windows service that should perform an action every, lets say, 60 seconds.
How is the best way to implement that main loop?
Implementations I've seen so far:
1) Using a Timer object that executes a delegate every xx seconds
2) Using ManualResetEvents (the implementation I've seen only executes once, but as far as I unders...