|
programming challenge: fewest characters |
Joel Davis
Member #3,425
April 2003
|
I'd love to see someone solve this in J (link) or APL, the most concise programming language in existance. (J is like APL without the need for a special font) |
Oscar Giner
Member #2,207
April 2002
|
Rick: look better. I use string three times. -- |
Rick
Member #3,572
June 2003
|
Sorry, missed it in those #defines. ======================================================== |
BAF
Member #2,981
December 2002
|
oh yeah? I just invented baf++. The compiler is still under development, but it has built in support for everything Its syntax is similar to c, but is as highlevel as anything can get. I have alraedy ported allegro 5 to it. #include <allegro5.h> read_mind(do_first_last_name_sorting_stuff()); END_OF_PROGRAM(())
|
Kitty Cat
Member #2,815
October 2002
|
Bah. I stole an advanced copy of Allegro 5 from Bob when he moved from Canada. It works in plain C. BTW, you're not taking advantage of hardware acceleration that way. -- |
Rick
Member #3,572
June 2003
|
Had to find the right .NET class that simulated a stl map
======================================================== |
Billybob
Member #3,136
January 2003
|
BAH, My code is perfect!
Quote: I made it compile but the output generated is not the one the problem defines Just because the program doesn't output like the example, doesn't mean it isn't correct. The example given by the OP is incorrect: Quote: generate a table where anyone with the same last name is assumed to be related and the first names put underneath the last name, indented by one tab. EDIT: Code updated as of...6:59 PM PST
|
ReyBrujo
Moderator
January 2001
|
Hmm... I didn't like this Perl code too much. I notice I am the only one that respect the output format (if only one name with a surname, print them in the same line, otherwise print the surname first, and then all the names below) I use a hash to prevent repeating surnames too.
-- |
Matthew Leverton
Supreme Loser
January 1999
|
Quote: I notice I am the only one that respect the output format (if only one name with a surname, print them in the same line, otherwise print the surname first, and then all the names below) Mine is right! |
ReyBrujo
Moderator
January 2001
|
Awww... that is why I still don't understand PHP -- |
X-G
Member #856
December 2000
|
Quote: I notice I am the only one that respect the output format Mine also respects that output format. Go back and read my code. What's that you say? You can't figure it out? -- |
ImLeftFooted
Member #3,935
October 2003
|
154 <Php> Matthew Leverton Values calculated using `cat foo | tr -d ' ' | tr -d '\t' | tr -d '\n' | wc -c` My entry:
I think I can safely say that mines the first thats trying to say something at the same time... Also note that the instructions said nothing about how the program had to exit... Its also attatched to preserve the tabs if someone wants to compile it |
kazzmir
Member #1,786
December 2001
|
meh, another losing entry.. ill try again in a different language.
|
X-G
Member #856
December 2000
|
Fear not! Me and Jolle are working on a compacted version of my Haskell entry above. So far we're down to 173 characters. -- |
Oscar Giner
Member #2,207
April 2002
|
Quote: I notice I am the only one that respect the output format (if only one name with a surname, print them in the same line, otherwise print the surname first, and then all the names below) And mine also respects it Quote:
364 <C++> Winston Ewert Note that Winston and Williams's code doesn't produce the correct output. Neither yours does (and it crashes) -- |
Mars
Member #971
February 2001
|
135 characters in Python, but the formating isn't right: i = [a.split() for a in file("n").readlines()] n = {} for a in i: try: n[a[1]] += [a[0]] except: n[a[1]] = [a[0]] for l,f in n.iteritems(): print l, "\n\t".join(f) 167 characters in Python with correct formatting: i = [a.split() for a in file("n").readlines()] n = {} for a in i: try: n[a[1]] += [a[0]] except: n[a[1]] = [a[0]] for l,f in n.iteritems(): if len(f) < 2: print l, f[0] else: print l, "\n\t".join([""]+f) The other Python entry doesn't get the formatting right and is unreadable and longer. Matthew, your Python interpreter is outdated. -- |
Matthew Leverton
Supreme Loser
January 1999
|
Actually, my entry is 148 if you use my shorter method. It just spits out some notices if you have PHP on strict "debug" mode. My nonconforming entry (placing all first names below last names) is 128. Surely someone do much better than that though... PHP has long names like "foreach", and I have to resort to using a trim(). It also doesn't have the shortcut stuff like: i = [a.split() for a in file("n").readlines()] |
Marcello
Member #1,860
January 2002
|
Quote: It also doesn't have the shortcut stuff like [...] ... Which is a good thing. Marcello |
X-G
Member #856
December 2000
|
Haskell is back again to save the day! z x (n:b) | n!!0 == x!!1 = [n!!0,"\n ",x!!0 ++ "\n " ++ n!!2] : b | 0 < 1 = n : z x b z [a,b] _ = [[b," ",a]] main = readFile "f" >>= putStr . unlines . map concat . foldr (z . words) [] . lines This little baby clocks in at 143 non-whitespace characters and gets the formatting right. Shortest so far, then. Co-produced by me and Jolle. -- |
Matthew Leverton
Supreme Loser
January 1999
|
Mine's 144 now. If PHP just didn't require those <? ?> tags. However, I think essential white space (anything required for parsing or output) should count. Mine runs like this: <?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";?> 149 bytes short. X-G: Does yours output a tab character? |
ReyBrujo
Moderator
January 2001
|
If you turn warnings off, this version of Perl would work as well, and has only 205 characters:
-- |
X-G
Member #856
December 2000
|
Quote: X-G: Does yours output a tab character? I'd tell you, but I'm running out of posts. (Yes.) -- |
Matthew Leverton
Supreme Loser
January 1999
|
<? foreach (file("n") as $l) { $p = split(" | ", $l); $n[$p[1]][] = $p[0]; } foreach ($n as $a=>$z) foreach ($z as $i=>$p) echo ($z[1] ? $i?" ":"$a " : "$a ") ."$p "; ?> Splendid! Mine's 134 now by the cat/wc count. I'm using literal tabs and newlines instead of \codes now. (Although, I still say it's no fair to discard required whitespace...) I don't know if I can make it any shorter without rethinking. I better get back to some real work. |
23yrold3yrold
Member #1,134
March 2001
|
Quote: Splended! I didn't know there was a splending contest ... -- |
Matthew Leverton
Supreme Loser
January 1999
|
Eh? Where's your C++ STL is teh foo code? |
|
|