|
programming challenge: fewest characters |
Derezo
Member #1,666
April 2001
|
It's official: I now hate perl. "He who controls the stuffing controls the Universe" |
kazzmir
Member #1,786
December 2001
|
Quote: It's official: I now hate perl. I used to hate perl as well until I was forced to learn it a little while ago. Dude. its. awesome. Its such a great language to manipulating text in. I havent found an language that can manipulate text in better, including c,c++,java,python,scheme,shell. |
ReyBrujo
Moderator
January 2001
|
Well, maybe because PERL was created exactly for that (Practical Extraction and Report Language). And Colin is doing a very clever thing in push @{$h{$_[1]}}, $_[0];: he is using a hashed list in which every value is an array, and then using the $" variable (which I did learn now it keeps the default separator to be used in an array when printing it whole; by default it is a space, but he changes it to "\n\t") to make Perl output it directly. In my code, I use a hashed list of strings instead, so I need an extra split to convert the string into an array. I guess it is still possible to make it < 100 characters. Here is my possibly last version, using his suggestion to turn the while into a map (both basically do the same, but the later needs less characters):
107. -- |
Billybob
Member #3,136
January 2003
|
/me looks at perl.
|
23yrold3yrold
Member #1,134
March 2001
|
It's true; Perl really does look like a cartoon character swearing. Anyway, good job getting it down to 107. Holy crap. -- |
Colin O'Leary
Member #3,233
February 2003
|
Perl's not so bad if you're not using one character variables, (ab)using map instead of while, and using default variables everywhere. Here's a more readable version (assuming you know Perl )
And by the way, 99 characters (not including whitespace):
Naming the file "0" saves a pair of quotes. |
ImLeftFooted
Member #3,935
October 2003
|
#1 Quote:
\\\\\\\\\\\\\\\\\\\\\\\\\\\` \\\\\\\\\\\\\\\ \||||||||||||||||||||||||||| \||||||||||||||| \|||@@@@||@@@@||@@@@||@||||| \|||@@@@||@@@@|| \|||@||@||@|||||@||@||@||||| \|||@||@||@||@|| \|||@@@@||@@@|||@@@@||@||||| \|||@@@@||@@@@|| \|||@|||||@|||||@|@|||@||||| \||||||@|||||@|| \|||@|||||@@@@||@||@||@@@@|| \||||||@|||||@|| \||||||||||||||||||||||||||| \|||||||||||||||
- - - - Colin O'Leary |
Thomas Fjellstrom
Member #476
June 2000
|
Damn you Colin, steal my thunder >:E Perl: map { split; push @{$h{$_[1]}}, $_[0] } `cat n`; for $l (keys %h) { print "$l " . shift(@{$h{$l}}) . "\n"; print "\t$_\n" for (@{$h{$l}}); } 114 chars (give or take). And thats without resorting to that evil crud edit: moding for that last while loop... map { split; push @{$h{$_[1]}}, $_[0] } `cat n`; $"=" "; print @$a < 2 ? "$k @$a[0] " : "$k @$a " while ($k, $a) = each %h Now to count... woo hoo, 95 -- |
ReyBrujo
Moderator
January 2001
|
But it forces you to have cat... -- |
Thomas Fjellstrom
Member #476
June 2000
|
I don't see a problem with that. If you have perl on windows, you're going to know how to fix it -- |
CascoOscuro
Member #4,966
August 2004
|
Quote:
jane fonda In prolog: surname(jane,fonda). surname(chuck,norris). surname(ted,fonda). surname(kyle,boop). And then in the interpreter command line write surname(X,fonda). (for example). |
Rash
Member #2,374
May 2002
|
Only Oscar Giner and I have posted correct C++ code. |
ImLeftFooted
Member #3,935
October 2003
|
Quote:
map { Now to count... woo hoo, 95 Curse you:P. Now i have to change the 99 to 95. By the way, did you purposely leave off the last " there, or was it a copying error? |
ReyBrujo
Moderator
January 2001
|
Hmm... well, now that we are cheating map { split; push @{$h{$_[1]}}, $_[0] } <>; $"=" "; print @$a < 2 ? "$k @$a[0] " : "$k @$a " while ($k, $a) = each %h Execute it like cat file.txt | perl test.pl. Here is the 91 characters entry Colins' was talking about. -- |
ImLeftFooted
Member #3,935
October 2003
|
I think that shouldnt be allowed... main(int, char **v) { printf(v[1]); } Comes in at 32 Edit: |
ReyBrujo
Moderator
January 2001
|
Well, I just don't agree with the idea of using external aid, like cat. He might later change `cat n` with `c n` and say you need to rename cat to c for it to work -- |
ImLeftFooted
Member #3,935
October 2003
|
Got it down to 11, using a custom compile command: [code entry.cpp] The compile command is: Edit: Edit2: Make that 10 characters |
Wetimer
Member #1,622
November 2001
|
Actually... While we are doing wierd cheats. Define the entire program as a preprocessor symbol. You won't be able to include, so you'll have to provide your own prototypes and such. But you should be able to define the symbol a as your entire program, there by doing it in one letter. <code>if(Windows.State = Crash) Computer.halt();</code> |
Thomas Fjellstrom
Member #476
June 2000
|
Oh come on, cat in perl is not a weird cheat Quote: By the way, did you purposely leave off the last " there, or was it a copying error? no error, just changed the formatting, colin's dsiplays wrong too. Has to do with that $" variable. the highligter thinks it starts a string. -- |
|
|