Thank you for your entries. Here is my response.
I'm currently writing a quick solution for Euler Problem #4 where one must find the largest palindromic number from the product of two 3-digit numbers.
To identify if a number is palindromic, you would obviously compare a reverse of the number with the original.
Since C# doesn't have a ...
Hi, I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works:
DEV='http://some/svn/server/'
BRANCH='some/repos/branches/'
LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r`
LAST_UPDATE=${LAST_UPDATE:0:10}
But ...
So I got asked today what was the best way to find the closes match within a collection.
For example, you've got an array like this:
1, 3, 8, 10, 13, ...
What number is closest to 4?
Collection is numerical, unordered and can be anything. Same with the number to match.
Lets see what we can come up with, from the various languages o...
Implement an algorithm to merge an arbitrary number of sorted lists into one sorted list. The aim is to create the smallest working programme, in whatever language you like.
For example:
input: ((1, 4, 7), (2, 5, 8), (3, 6, 9))
output: (1, 2, 3, 4, 5, 6, 7, 8, 9)
input: ((1, 10), (), (2, 5, 6, 7))
output: (1, 2, 5, 6, 7, 10)
Note:...
For my theory of computing languages class, we got a homework assignment to implement a piece of code in a language that only has while statements for flow control (no if statements). This is mainly to prove that you can write a Turing-complete language with only a while loop.
For those of you who can understand language grammars, here...
I have a list of lists that looks like this:
[['Tom', 'Dick'], ['Harry', 'John', 'Mike'], ['Bob']]
and I want to turn it into a dictionary where each key is a name and each value is a number corresponding to the position of its sublist in the list:
{'Tom': 0, 'Dick': 0, 'Harry': 1, 'John': 1, 'Mike': 1, 'Bob': 2}
I tried various li...
Search:
Scripting+Language Web+Pages Applications
Results:
...scripting language originally...producing dynamic web pages. It has...graphical applications....purpose scripting language that is...d creating web pages as output...
Suppose I want a value that represents the amount of characters to allow as padding on eit...
Given a list of assorted length words, what is the best way to find the maximum length of any words?
For example, the following should return 6
findMaxLen("a,set,of,random,words")
Of course, it's fairly trivial to do this...
<cffunction name="findMaxLen" returntype="Numeric">
<cfset var CurMax = 0 />
<cfset var CurItem = 0...
Decode the following string and encode it back.
Any programming language is welcome, the point is to create a solution with the minimum amount of characters.
Formatting and new lines does not count toward the char count.
Here's the message:
1010100 1101000 1100101 1110010 1100101 1100001 1110010 1100101 110001 110000 1110100...
Inspired by http://codegolf.com/prime-factors, try to solve this problem using the least number of keystrokes.
Sadly, you can only compete with Perl/PHP/Python/Ruby and I would love to see this problem solved in other not so traditional languages.
...
Golf - implement a simple templating scheme.
Expansions are:
%KEY% -> VALUE
%% -> %
Command line arguments:
ARG1: dictionary file, formatted in the key=value style as in example
ARG2: template file
Here my not quite golf attempt(python): 261 chars.
import sys
dd = dict([ll.split("=",2) for ll in open( sys.argv[1],'r') if l...
In response to this question asking about hex to (raw) binary conversion, a comment suggested that it could be solved in "5-10 lines of C, or any other language."
I'm sure that for (some) scripting languages that could be achieved, and would like to see how. Can we prove that comment true, for C, too?
NB: this doesn't mean hex to ASCI...
Imagine a user that would like to put a form on their website that would allow a website visitor to upload a file and a simple message, which will immediately be emailed (ie, the file is not stored on the server, or if it is then only temporarily) as a file attachment with the note in the message body.
What is the simplest way to accomp...
I made the ultimate laugh generator using these rules. Can you implement it in your favorite language in a clever manner?
Rules:
On every iteration, the following transformations occur.
H -> AH
A -> HA
AA -> HA
HH -> AH
AAH -> HA
HAA -> AH
n = 0 | H
n = 1 | AH
n = 2 | HAAH
n = 3 | AHAH
n = 4 | HAAHHAAH
n = 5 | AHAHHA
n...
I'm looking for the shortest or most optimized solution for a simple game that generates a random number from 1 to 10 and then asks a user to enter their guess. If the user guesses the number then it's a win, if they don't guess then the program should say that it was either more or less than that.
Here's my solution to this:
#c:\Perl...
The newspaper for the Computer Science-line at my school (called readme, is's norwegian, page 19) had a fun competition:
Write the shortest possible Java-code for this problem:
Take in an integer (as a string in the first entry of a string array, since the Java main method only takes a string array) as an argument, and write out fir...
I'm working on a bookmarklet, and thought I'd throw down a challenge: how to inject an external javascript file from a link in as few characters as possible.
Here's the shortest I was able to come up with:
javascript:(function(d){d.body.appendChild(d.createElement('script')).src='URL'})(document)
That's 88 characters without the URL....
Anything that saves a few characters and produces horrible, unreadable code is fair game.
My favourite is cheating spacing with the ternary operator. If you're testing a question-mark-method (like .nil?), the only place you need a space is after the second question mark:
x.odd?? "odd":"even"
...
The problem:
>>> a = dict(a=1,b=2 )
>>> b = dict( b=3,c=2)
>>> c = ???
c = {'a': 1, 'b': 5, 'c': 2}
So, the idea is two add to dictionaries by int/float values in the shortest form.
Here's one solution that I've devised, but I don't like it, cause it's long:
c = dict([(i,a.get(i,0) + b.get(i,0)) for i in set(a.keys()+b.keys()...
If a picture's worth 1000 words, how much of a picture can you fit in 140 characters?
Note: That's it folks! Bounty deadline is here, and after some tough deliberation, I have decided that Boojum's entry just barely edged out Sam Hocevar's. I will post more detailed notes once I've had a chance to write them up. Of course, everyone shou...