|XP is just a number|
Golf: 3 hole golf gameby theroninwins (Friar)
|on Nov 16, 2004 at 07:28 UTC||Need Help??|
While browsing through the internet I found this and thought it would perfectly fit here for a rainy day or a good challenge:
The object of the Challenge is to solve a few programming tasks using the shortest programs you can think off
All programs must work on current perl (most likely programs you write on another version will be just fine, so don't directly go downloading a different perl)
All programs are filters. They must read input from STDIN, and send output to STDOUT. All input lines are properly newline terminated, and do not contain binary 0. All input files have a total size so that they will fit comfortably in memory and still allow you ample memory to play with.
All output lines must likewise be properly newline terminated. Nothing must appear on STDERR. The average runtime of the program must be finite, but may be arbitrarily long.
You must assume total memory is < 2**32 bytes (this e.g. implies sizes of arbitrary datastructures can be represented in a plain integer, and that you must not try to generate arbitrarily big datastructures).
The program must be written as one or more lines. The score for each hole is the total number of characters you need (smaller is better). If your program is more than one line, you must count the newlines inbetween as one character each. The #! line is not counted. If you use options on the #! line, the options themselves are counted, including the leading space and -
The program may only use the perl executable, no other executables on the system are allowed (in particular, you must not use the programs implementing the other holes. The program may use itself though). You may use any of the current perl standard core modules. Your solution must be portable in the sense that it should work on all versions of current perl everywhere. You may assume ASCII as character set and must not use any of the unicode specific semantics
Sort a set of lines, but with a twist.
When sorting a set of lines, humans like to see the numeric parts of a line sorted numerically and the alphabetical parts case insensitive. For the numeric parts you may ignore the possibility of negative numbers, floating point numbers and leading zeros, the numbers however are almost unconstrained in length. In other words, a sequence of one or more digits plays the same sort of role as some kind of single character, and such a sequence sorts before all normal letters, but among themselves they are ordered by numerical value. Example:
1 < A < amstelveen < Amsterdam < Amsterdam5 < Amsterdam40 < Amsterdamned
You are free in how you order e.g. fOo versus FoO or a digit versus space.
* watch out, the original version of this question did not request case insensitivity.
* watch out, the original version of this question allowed leading zeros in the number parts, but that made programs substantially more complicated and less fun. While this change won't invalidate any existing solution, maybe you can do better now....
* The strings can also be things like: 57amstel25venn865314457646576532325988watte
* Remember, if your program is going to generate (temporary) strings of size > 2**32, your program will be rejected. So avoid things like
"a865314457646576532325988watte" =~ /(\d+)/; 0 x $1;
Outputs some random permutation of the input lines. Each permutation must be equally likely over many runs.
print 2 lines each randomly chosen from the input, however the two must not come from the same line in the input. You may assume the input is 2 lines or more. each pair of outputlines must be equally likely, and their order itself also random
Some more hints about randomness:
* using non-consistent sort-functions will not be accepted. The results are not random on almost any sort implementation and can even coredump some implementations.
* You must not ignore the fact that two calls to rand can in principle return the exact same number twice.
* You may assume each value returned by rand is equally likely.
Here is a program to pre-screen your entries. (given at the challenge)
Please post scores of each hole and the total
I have some results but i don't want to post them yet, if someone feels he/she really wants to see them I can give them to him/her. If I would post them, it would only spoil the fun.