language-agnostic

Given an array of numbers, except for one number all the others, occur twice. Give an algorithm to find that number which occurs only once in the array.

What I can think of is: Algo: Have a hash table which will store the number and its associated count Parse the array and increment the count for number. Now parse the hash table to get the number whose count is 1. Can you guys think of solution better than this. With O(n) runtime and using no extra space ...

How do you deal with your past programming atrocities?

None of us started off as experts (and most of us still aren't). Sure, we all knew how to write programs in our preferred languages, but writing quality applications and writing syntactically correct programs are two very different things. We work, we learn, we struggle, we keep learning, and eventually we reach that threshold where ot...

What is the ideal timeframe for testing code

I'm currently working on a critical monthly Accounts payable report. This report i just wrote will be the basis for my client in which how much is he going to pay to his vendors. So far i have spent about 5 hrs building automated tests and found zero errors so far. Do you think i am already spending too much time testing? What should be ...

Motion planning without a graph across an infinite plane

An object is positioned at A and wants to move to B. I want to calculate a movement vector there that doesn't move within the distance D of the to-be-avoided points in array C. So if the move vector (B-A) normalized and multiplied with the objects speed would bring it within D of any point in C the vector is rotated so that it doesn't. ...

How can I eliminate left recursion in the following grammar?

Here's the grammar, which is supposed to describe a language of nested braces with commas as delimiters: L ::= {L} | L,L | A few more examples of strings I'd expect the grammar to accept and reject: Accept: {,{,,{,}},,{,}} {{{{}}}} {,{}} Reject: {}{} {,{}{}} {{},{} ...

Opposite of Bitwise OR operation.

I compute c = a 'OR' b // bitwise OR operation here Now given only values of c and b how can I compute the original value of a? ...

Is Sleep() evil?

First of all, there are many cases where Sleep() is misused, for example to "synchronize" threads or to regularily poll a value where a notification function would do (In Win32 WaitForSingleObject for example) But what about other use cases? Is Sleep always evil? If no, what are good use cases for Sleep? If yes, why do almost all langua...

Handling close-to-impossible collisions on should-be-unique values

There are many systems that depend on the uniqueness of some particular value. Anything that uses GUIDs comes to mind (eg. the Windows registry or other databases), but also things that create a hash from an object to identify it and thus need this hash to be unique. A hash table usually doesn't mind if two objects have the same hash be...

Are regular expressions worth the hassle?

It strikes me that regular expressions are not understood well by the majority of developers. It also strikes me that for a lot of problems where regular expressions are used, a lump of code could be used instead. Granted, it might be slower and be 20 lines for something like email validation, but if performance of the code is not desper...

Are salts useless for security if the attacker knows them?

Let's say I have a table of users set up like this: CREATE TABLE `users` ( `id` INTEGER PRIMARY KEY, `name` TEXT, `hashed_password` TEXT, `salt` TEXT ) When a user is created, a randomly-generated salt is produced and stored in the database alongside the results of something like get_hash(salt + plaintext_password). I...

How does one deal with Hofstadter's law?

When estimating tasks, how does one break from the grip of Hofstadter's law? ...

Where does the compiler spend most of its time during parsing ?

I read in Sebesta book, that the compiler spends most of its time in lexing source code. So, optimizing the lexer is a necessity, unlike the syntax analyzer. If this is true, why lexical analysis stage takes so much time compared to syntax analysis in general ? I mean by syntax analysis the the derivation process. ...

What's the best way to provide a web shop application to multiple customers?

If I had a web shop application and I'd want to provide it to multiple customers, who sell their products from the web shop, how would I design such application when it comes to deployment? One application with one database on a central server. Every data row has a customer ID which states to which customer ("shop instance") it belongs...

What code don't you test?

Possible Duplicate: How deep are your unit tests? Ok, so it's common wisdom that it's impractical (and maybe not even preferable) to get 100% test coverage. In my experience, there's some code that's simply more trouble to test than it is practical to do so. I've kind of developed an intuition about this. But my team is sort ...

Reconstructing state from time series data events

For a particular project, we acquire data for a number of events and collect variables about those events at the same time. After the data has been collected, we perform a user-customizable analysis on said data to determine whatever it is that the user is interested in. The data is collected in a form similar to this: Timestamp E...

compilers for languages from 1950's and 1960's

i am trying to find the best compilers (if they are actually available) for the following languages: ALGOL 60 TRAC TELCOMP Superplan BACAIC i don't know if any of these are still around, but it would be very helpful to get any feedback on where i could locate these. ...

Does it exist: Repeated Code Finder?

In the near future, I will be inheriting a somewhat large project. I've been making some small updates to it recently, and noticed that parts of it could use some refactoring, since there are methods that perform the same operation with a small difference. I was wondering if there is a tool that will take a bunch of source code and f...

Calculating Screen Space Error

I'm currently working on a Level of detail system for an XNA game, the system subdivides triangles with high screen space error and merges triangles with low screen space error. World Space Error is a heuristic which estimates the error that this triangle has, so for example if there is a triangle which is on an almost flat surface, it'...

What to do, if debug behaviour differs from normal execution?

I have a problem with debugging sessions. My program executes very well in a debug session but if I start a normal run, it behaves completely different. The problem is, that I cannot say, why it acts different. One possible reason is the slower execution time because you alway have to press F6 or so. I tried to insert Thread.sleep(1000)...

For what kind of problems do you write a DSL?

I'm just curious about Domain-Specific Languages. I have seen them several times in articles, and it seems that they can be used outside assurance or bank data definition problems. So I come to SO to have some concrete input. Did you ever use a DSL? Write one. If yes, what's it feel like? Do you think one of your projects could be be...