How do I program using cat?
In this xkcd comic: they mention that real programmers use cat. Well, I was asking myself: how could you program using the cat command? ...
In this xkcd comic: they mention that real programmers use cat. Well, I was asking myself: how could you program using the cat command? ...
Challenge Here is the challenge (of my own invention, though I wouldn't be surprised if it has previously appeared elsewhere on the web). Write a function that takes a single argument that is a string representation of a simple mathematical expression and evaluates it as a floating point value. A "simple expression" may in...
Spent me 3 hours to get a good regex finished for parsing these 3 main possible situations. Redden, Taylor Captain Hasting Jr. Redden, Taylor Hasting Jr. Redden, Taylor Hasting full, l, f, m1, m2, s = /your_regex_here/.match("Redden, Taylor Captain Hasting Jr.").to_a I want to see what other possible answers there are beside min...
As a trivia question, I'm trying to write a javascript function that returns its variable number of arguments in sorted (normal lexicographic) order. Having never dealt with javascript before, I came across the "arguments" object, which seems to work somewhat like an array but without having the standard array functions -- therefore I s...
I'm adding a function to my own personal toolkit lib to do simple CSV to HTML table conversion. I would like the smallest possible piece of code to do this in C#, and it needs to be able to handle CSV files in excess of ~500mb. So far my two contenders are splitting csv into arrays by delimiters and building HTML output search-r...
My try at code golfing. The problem of finding the minimum value of ∑W_i*|X-X_i| reduces to finding the weighted median of a list of x[i] with weights w[i] (see below for definition). How will you do that with a shortest, simplest and most beautiful program? Here's how my code looked originally (explanation is in the answer to the ques...
Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence. After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Python, as seen here (though that ...
Rules Your program must have two modes: encoding and decoding. When encoding: Your program must take as input some human readable Latin1 text, presumably English. It doesn't matter if you ignore punctuation marks. You only need to worry about actual English words, not L337. Any accented letters may be converted to simple ASCII. You m...
This should be easy. here's my array (rather, a method of generating representative test arrays): >>> ri = numpy.random.randint >>> ri2 = lambda x: ''.join(ri(0,9,x).astype('S')) >>> a = array([float(ri2(x)+ '.' + ri2(y)) for x,y in ri(1,10,(10,2))]) >>> a array([ 7.99914000e+01, 2.08000000e+01, 3.94000000e+02, 4.661000...
Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive number], "d", positive number entity ::= roll | positive number expression ::= entity {...
I've already worked out this solution for myself with PHP, but I'm curious how it could be done differently - better even. The two languages I'm primarily interested in are PHP and Javascript, but I'd be interested in seeing how quickly this could be done in any other major language today as well (mostly C#, Java, etc). Return only wor...
I've just tried to create the smallest possible language interpreter. Would you like to join and try? Rules of the game: You should specify a programming language you're interpreting. If it's a language you invented, it should come with a list of commands in the comments. Your code should start with example program and data assigned t...
I just came across this little problem on UVA's Online Judge and thought, that it may be a good candidate for a little code-golf. The problem: You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular...
Here's my (code golf) challenge: Take two arrays of bytes and determine if the second array is a substring of the first. If it is, output the index at which the contents of the second array appear in the first. If you do not find the second array in the first, then output -1. Example Input: { 63, 101, 245, 215, 0 } { 245, 215 } Expecte...
Given the following list of presidents do a top ten word count in the smallest program possible: INPUT FILE Washington Washington Adams Jefferson Jefferson Madison Madison Monroe Monroe John Quincy Adams Jackson Jackson Van Buren Harrison DIES Tyler Polk Taylor ...
Hi all, I have a method which I would like to invoke asynchronously: void Foo() { } I can indeed invoke this asynchronously by the following: delegate void DVoidMethod(); DVoidMethod FooDelegate = new DVoidMethod(Foo); FooDelegate.BeginInvoke(null,null); Has anyone got any alternatives? I think three lines of code is too much? ...
If you want to check if something matches a regex, if so, print the first group, you do.. import re match = re.match("(\d+)g", "123g") if match is not None: print match.group(1) This is completely pedantic, but the intermediate match variable is a bit annoying.. Languages like Perl do this by creating new $1..$9 variables for mat...
Does anyone remember years ago in magazines like Byte where people competed to produce the most functional piece of code written in a single line of code? I remember games like Pole Position with scrollng text, etc. and fractal graphics being done this way. Granted modern languages like C# and Java an endless amount in one statement, d...
I was wondering if anyone knew of a "World's Smallest Chess Program". By this I mean a text based program that can play a game of chess following all the rules (castling, en passent, underpromotion, game ends with mate(stale), draw by repetition or insufficent material) in the least amount of code. I found some forums on this when I ch...
Generate a list of lists (or print, I don't mind) a Pascal's Triangle of size N with the least lines of code possible! Here goes my attempt (118 characters in python 2.6 using a trick): c,z,k=locals,[0],'_[1]' p=lambda n:[len(c()[k])and map(sum,zip(z+c()[k][-1],c()[k][-1]+z))or[1]for _ in range(n)] Explanation: the first element of...