|
programming challenge: fewest characters |
kazzmir
Member #1,786
December 2001
|
Its time for another programming challenge. The idea is to solve the given question with the fewest number of characters, in any language. Whitespace will be removed for counting, so dont bother to make your code look clean in the thread. The problem: jane fonda chuck norris ted fonda kyle boop The result should look like fonda jane ted boop kyle norris chuck Ordering of last names is arbitrary. Ill post an answer later on. Remember, any language and fewest number of characters. Or feel free to come up with a better problem. |
spellcaster
Member #1,493
September 2001
|
Quote: Whitespace will be removed for counting, so dont bother to make your code look clean in the thread. Here's my whitespace version of the code: Since whitespace are not counted, I think I won. -- |
Kris Allen
Member #4,639
May 2004
|
Quote: Since whitespace are not counted, I think I won. Not if your whitespace program doesn't do what it needs to, which I don't think it does! - Kris |
Matthew Leverton
Supreme Loser
January 1999
|
I tried it out in my secret compiler, and it worked. But really, there should be a limitation on language used, or else there's no fair way to compare entries. |
Rick
Member #3,572
June 2003
|
I agree. You could use VB.NET and it would kill most C/C++ programs due to the fact VB.NET does most of the work for you. It's not really fair. When you say table, what do you mean? You want this in a database, or just back into another file? ======================================================== |
Billybob
Member #3,136
January 2003
|
I dunno, i guess I'll try:
|
ReyBrujo
Moderator
January 2001
|
I can do it in Ruby, Perl or VB. In C or C++ would take too much. Off home right now, will post those solutions in around 3 hours (remember, I voted the over 4 hours of travelling to work in a poll here time ago ). -- |
X-G
Member #856
December 2000
|
Obfuscated Haskell for everyone!
EDIT: Made it somewhat shorter. -- |
Matthew Leverton
Supreme Loser
January 1999
|
<? foreach (file("n") as $l) { $p = split(" |\n", $l); $n[$p[1]][] = $p[0]; } foreach ($n as $a=>$z) foreach ($z as $i=>$p) echo ($z[1] ? $i?"\t":"$a\n\t" : "$a ") ."$p\n"; ?> Note: disable debug "notices" when running. |
BAF
Member #2,981
December 2002
|
baf langauge (*%)#*)R(#*()#F*I()R#)T#*%()#*)%&(#*&(*)R#^T#@^#T)"|::|:}|:}{|#58927389u*(&*(#%&(*35 and in elite c++: (care of l33t-sp34k g3n3r4t0r)
remember, you have to use the elite g++ port... |
LSd016
Member #3,561
May 2003
|
#/bin/bash cat file.txt|decapitalise|sort|dostuff|playwith > /dev/tty1
____________________________________________ |
Wetimer
Member #1,622
November 2001
|
Well, I thought about doing it in C++, but William Heatley already did so, I took his code and chopped it down a little. Wacko C++
<code>if(Windows.State = Crash) Computer.halt();</code> |
Goodbytes
Member #448
June 2000
|
|
Wetimer
Member #1,622
November 2001
|
Except while Whitespace can deal with input, it cannot read from files, which is a requirement. <code>if(Windows.State = Crash) Computer.halt();</code> |
Oscar Giner
Member #2,207
April 2002
|
Willam: your code doesn't compile I made it compile but the output generated is not the one the problem defines (same would apply to derivative work ). Here's mine. Base on William's, but it compiles and generates correct output:
[edit] -- |
Joel Davis
Member #3,425
April 2003
|
Python's list comprehensions rock! import string n = dict([string.split(i) for i in open('names.txt').readlines()]) for x,y in dict([(v,string.join( ['']+[k for k in n.keys() if v==n[k] ],"\n "))for v in n.values() ]).iteritems(): print x,y And so clear and readable.. heh --Joel |
Matthew Leverton
Supreme Loser
January 1999
|
Bah, C++ is so primitive compared to PHP. I would think a Perl nerd could get the shortest working code. Joel: I get invalid syntax on yours... |
spellcaster
Member #1,493
September 2001
|
Quote: Except while Whitespace can deal with input, it cannot read from files, which is a requirement. Why? There's no requirement that you have to load that file, so a type foo.txt > parse
does the trick of reading the names from that file. -- |
Krzysztof Kluczek
Member #4,191
January 2004
|
Solution to this problem in Tytwggfdtyuqfef++++-- programming language: Nobody said that inventing new high level language is forbidden - specification isn't complete yet, but it already can solve this problem. (and no, language name is not a polish word) ________ |
Joel Davis
Member #3,425
April 2003
|
Hmm.. i'm using python 2.3.4, I think list comprehensions are pretty recent, anything above python 2.1 should work tho... And perl could probably do way less characters, it's just sooo distasteful. edit: oops, i'm using iteritem() so you need python 2.1 for that edit2: attached the py file as an attachment so you don't have to worry about formatting cut/paste errors. |
LSd016
Member #3,561
May 2003
|
You lie. "Tytwggfdtyuqfef" == "barman, pour me another!" ____________________________________________ |
Rick
Member #3,572
June 2003
|
Quote: The idea is to solve the given question with the fewest number of characters
Quote:
#define F(a, b, c) for(a::iterator b = c.begin(); b != c.end(); ++b) I'm assuming he didn't think about this as being whitespace. If that was the case you could do everything with 1 call. [EDIT] ======================================================== |
Matthew Leverton
Supreme Loser
January 1999
|
Yeah, yeah, yeah. Enough of the funnies. Ok, File "test.py", line 2 n = dict([string.split(i) for i in open('names.txt').readlines()]) ^ SyntaxError: invalid syntax Disclaimer: I'm not familiar with Python. |
Oscar Giner
Member #2,207
April 2002
|
Quote: I'm assuming he didn't think about this as being whitespace. If that was the case you could do everything with 1 call. No, that part also counts. But it's smaller doing that. -- |
Rick
Member #3,572
June 2003
|
I would take out #define S string since you only use string once in your code, you are wasting 8 characters. That's why I thought you didn't think it counted. Trying to help. ======================================================== |
|
|