language-agnostic

Function to return date of Easter for the given year

So, here's a funny little programming challenge. I was writing a quick method to determine all the market holidays for a particular year, and then I started reading about Easter and discovered just how crazy* the logic is for determining its date--the first Sunday after the Paschal Full Moon following the spring equinox! Does anybody kno...

Whats the point of dual-licensing?

I am wondering what the point of dual licensing is whenever the two licenses in question are both open source licenses. For instance, jQuery provides their library under either the MIT or GPL license. What is the point of doing this? Also, I've seen http://stackoverflow.com/questions/1174271/what-happens-when-open-source-software-has-...

When your method fails, but succeeds... Would you return a failure or a success?

I doubt a definite answer exists but I'm quite interested in different opinions on the subject. A communiti wiki therefore. You're designing a method. It serves a purpose, that's why you're designing it in the first place. A caller uses your method and the method fails, but, lo and behold, the ultimate purpose that exuse the existence o...

Detecting patterns in waves

Hello all! I'm trying to read a image from a electrocardiography and detect each one of the main waves in it (P wave, QRS complex and T wave). Now I can read the image and get a vector like (4.2; 4.4; 4.9; 4.7; ...) representative of the values in the electrocardiography, what is half of the problem. I need a algorithm that can walk thr...

What's your longest-lasting bug that you created or encountered?

What's the bug that you inadvertently created or encountered that remained undiscovered for the longest period of time? ...

Do you have genetic algorithm in production?

Is it good idea to use genetic algorithm in production? If you are using it: In what case? What pros for selecting subj? Can you easily add changes to algorithm? ...

Unit test documentation

I would like to know from those who document unit tests how they are documenting it. I understand that most TDD followers claim "the code speaks" and thus test documentation is not very important because code should be self-descriptive. Fair enough, but I would like to know how to document unit tests, not whether to document them at all....

Increase when smaller than, decrease when lower than

Out of curiosity, is there a (language independent*) way to make these two generic statements into one statement? if (a < b) a += x; else if (a > b) a -= x; May also be used as if (abs(b - a) < x) a = b; else if (a < b) a += x; else if (a > b) a -= x; Oh, now that I'm writing this I'm thinking of something like this: if (a != b) a...

Probability theory and project planning

Hello, everyone, I'm managing a project that has to be estimated, according to rough requirements and specifications. Because of that, the estimations on the specific features and tasks are set of discrete values, instead of just one discrete value (for example, between 10 and 20, instead of exactly 17). I'm curious, if I want to get a...

Code Golf: Piano

The challenge The shortest code by character count to output a part of a piano keyboard starting from input note in a given length. Input will be composed of a note ([ACDFG]#|[A-G]) to start printing the keyboard from and a positive number representing length of keys to print including the first note. The first key should be printed i...

REST interface usage for multiple resources

I am currently adding a REST API over http to an online service and I am confronted with a very simple problem for which I cannot find an answer that satisfies me: I have mainly 2 resources: 'user' and 'reports', as you would have guessed reports are associated to users (to one and only one, = foreign key in my db) Anyway I have this u...

Elegant command-parsing in an OOP-based text game

I'm playing with writing a MUD/text adventure (please don't laugh) in Ruby. Can anyone give me any pointers towards an elegant, oop-based solution to parsing input text? We're talking about nothing more complex than "put wand on table", here. But everything needs to be soft; I want to extend the command set painlessly, later. M...

How do Factories and Patterns relate?

I was just reading a thread on SO that was discussing the merits of Singleton vs. Static Classes. Some people mentioned that pattern X appeared to be more of a 'factory' rather than a Singleton 'pattern'. What are the differences between a 'factory' and a 'design pattern'? ...

How does this work? Weird Towers of Hanoi Solution

I was lost on the internet when I discovered this unusual, iterative solution to the towers of Hanoi: for (int x=1; x < (1 << nDisks); x++) { FromPole = (x&x-1)%3; ToPole = ((x|x-1)+1)%3; moveDisk(FromPole,ToPole); } This post also has similar Delphi code in one of the answers. However, for the life of me, ...

What are efficient ways to (re)familiarize yourself with a language?

I've been programming in .NET C# almost exclusively for the past 7 months or so. Before that, most of my programming had been in C++ (from school). At work, I will likely be needing to do a whole bunch of C in the next few months. Most of my exposure to C comes from micro-controllers and stuff I find on the internet. I understand the syn...

Zig Zag Decoding

In the google protocol buffers encoding overview, they introduce something called "Zig Zag Encoding", this takes signed numbers, which have a small magnitude, and creates a series of unsigned numbers which have a small magnitude. For example Encoded => Plain 0 => 0 1 => -1 2 => 1 3 => -2 4 => 2 5 => -3 6 => 3 And so on. The encoding ...

Why is it called a 'String'?

Possible Duplicate: The History Behind the Definition of a String In most programming languages a string is a sequence of characters. Why is it named that? The earliest instance of it being called a string is Algol 60 (as far as I know). Question posed by Douglas Crockford in his talk today (will post when talk is online). ...

Why is writing a closed TCP socket worse than reading one?

When you read a closed TCP socket you get a regular error, i.e. it either returns 0 indicating EOF or -1 and an error code in errno which can be printed with perror. However, when you write a closed TCP socket the OS sends SIGPIPE to your app which will terminate the app if not caught. Why is writing the closed TCP socket worse than re...

Can the bigO of an algorithm be found programmatically by analyzing its perfs?

Note that I don't have a "problem" and I'm not looking for "another way to find the big O of my algorithm". What I'd like to know is if it would be possible write a program to which you'd pass data points that would all be perfs measurements of an algorithm for various input size: (n,time taken to solve problem for n) and that would the...

Any distributed parallel tree search algorithm suggestions?

Hello there, I'm writing a distributed Go/Gomoku bot. Basically the point is to distribute tree search onto many computers. With basic tree search algorithms like DFS this would be very simple, as I could just partition search space into subtrees. Though I'd rather have something more efficient, like mini-max with alpha-beta pruning - ...