language-agnostic

Where does one get data like Country:(list) State:(list)

As a programmer of data-entry forms of all kinds, I often find myself making fields for things like Country: <choose from list>, State: <choose from list>, Race/Ethnicity: <choose from list>. Consider: Perhaps a list the 50 United States names is an easy thing to find (does one include DC?) , but the countries are not. Nearly every site...

Implement a simple class in your favorite language.

I'm doing this to learn the syntax of different programming languages. So, how would you defined the following class along with with its operations in your favorite programming language? Image generated by http://yuml.me/ And a main method or equivalent to invoke it: For instance, for Java it would be: ... public static void ma...

Code Golf: MSM Random Number Generator

The challenge: The shortest code by character count that will generate a series of (pseudo)random numbers using the Middle-Square Method. The Middle-Square Method of (pseudo)random number generation was first suggested by John Von Neumann in 1946 and is defined as follows: Rn+1 = mid((Rn)2, m) For example: 34562 = 11943936 m...

Matching an IP address with an IP range?

I have a MySQL table setup as follows: +---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | ipaddress_s | varchar(15) | YES | MUL | NULL | | | ipaddres...

Creating huge images

My program has the feature to export a hi-res image of the working canvas to the disk. Users will frequently try to export images of about 20,000 x 10,000 pixels @ 32bpp which equals about 800MB. Add that to the serious memory consumption already going on in your average 3D CAD program and you'll pretty much guarantee an out-of-memory cr...

TCP Slow Start, Congestion Avoidance & Determining Bandwidth

Is there a formula someplace which can be used to determine the minimum number of segments / bytes which need to be transfered across a TCP connection to determine it's bandwidth and which takes into account Slow Start and Congestion Avoidance? I'm aware of the pathrate tool, but I want if possible something a bit simpler that I can inc...

Python script to calculate aded combinations from a dictionary

I am trying to write a script that will take a dictionary of items, each containing properties of values from 0 - 10, and add the various elements to select which combination of items achieve the desired totals. I also need the script to do this, using only items that have the same "slot" in common. For example: item_list = { 'item_1...

Programming Constructs History

Let us research and trace back the origins of language constructs. For example: Constructs Introduced from LISP If-Else Block :"The ubiquitous if-then-else structure, now taken for granted as an essential element of any programming language, was invented by McCarthy for use in Lisp, where it saw its first appearance in a more gener...

Help naming a class that has a single public method called Execute()

I have designed the following class that should work kind of like a method (usually the user will just run Execute()): public abstract class ??? { protected bool hasFailed = false; protected bool hasRun = false; public bool HasFailed { get { return hasFailed; } } public bool HasRun { get { return hasRun; } } privat...

Are ASCII diagrams worth my time?

Are ASCII diagrams within source code worth the time they take to create? I could create a bitmap diagram much faster, but images are much more difficult to in line in a source file (until VS2010). For the record, I'm not talking about decorative ASCII art. Here's an example of a diagram I recently created for my code that I probably ...

When to make a method static?

I'd like to know how people decide whether to define a method as static. I'm aware that a method can only be defined as static if it doesn't require access to instance fields. So let's say we have a method that does not access instance fields, do you always define such a method as static, or only if you need to call it statically (withou...

Is this a variation of the traveling salesman problem?

I'm interested in a function of two word lists, which would return an order agnostic edit distance between them. That is, the arguments would be two lists of (let's say space delimited) words and return value would be the minimum sum of the edit (or Levenshtein) distances of the words in the lists. Distance between "cat rat bat" and ...

Code Golf: Ghost Leg

The challenge The shortest code by character count that will output the numeric solution, given a number and a valid string pattern, using the Ghost Leg method. Examples Input: 3, "| | | | | | | | |-| |=| | | | | |-| | |-| |=| | | |-| |-| | |-|" Output: 2 Input: 2, "| | |=| | |-| |-| | | |-| | |" Output: 1 Clarifications ...

Word Jumble Algorithm

Given a word jumble (i.e. ofbaor), what would be an approach to unscramble the letters to create a real word (i.e. foobar)? I could see this having a couple of approaches, and I think I know how I'd do it in .NET, but I curious to see what some other solutions look like (always happy to see if my solution is optimal or not). This isn't...

Graph Algorithm To Find All Paths Between N Arbitrary Vertices

I have an graph with the following attributes: Undirected Not weighted Each vertex has a minimum of 2 and maximum of 6 edges connected to it. Vertex count will be < 100 Graph is static and no vertices/edges can be added/removed or edited. I'm looking for paths between a random subset of the vertices (at least 2). The paths should s...

Is currying just a way to avoid inheritance?

So my understanding of currying (based on SO questions) is that it lets you partially set parameters of a function and return a "truncated" function as a result. If you have a big hairy function takes 10 parameters and looks like function (location, type, gender, jumpShot%, SSN, vegetarian, salary) { //weird stuff } and you want ...

Generate combinations by order and fixed length.

Suppose there is array main[] = [a,b,c,....z]; a[] = [a1,a2,a3,....] , b[] = [b1,b2,b3,....] and so on. So if we generate combination in main.length of ordered then it looks like ..... a1 b1 c1, a1 b1 c2, a1 b1 c3 ...... a1 b2 c1, a1 b3 c1, ..... a2 b1 c1, a3 b1 c1, ..... and total count will be a.length * b.length * c.length .........

Is there any way to set or code breakpoints conditionally?

I've been wondering this for a while - is there a way to code/program breakpoints...? Conditionally? For example, can I specify something like - "when this variable becomes this value, break and open the debugger"? (Would be quite useful, especially in long loops when you want to debug loop execution of a late loop value.) I suppose thi...

Is there a programming language with no controls structures or operators?

Like Smalltalk or Lisp? EDIT Where control structures are like: Java Python if( condition ) { if cond: doSomething doSomething } Or Java Python while( true ) { while True: ...

What is a Flexible Array?

What is a Flexible Array, exactly? I can't find much on it. ...