Codegolf

From NoName e.V.
Revision as of 20:04, 18 September 2007 by 84.173.97.252 (talk) (→‎mxf: Perl)
Jump to navigation Jump to search

Challenge #1

<SdK> gibts wörter, die nach rot13 n anderes existierendes wort ergeben?

Testdatei: http://qu.cx/~mxf/web2.gz == /usr/share/dict/web2
Gepiped durch wc -l sollte 154 rausfallen, da einige Wörter doppelt vorkommen. 
Falls Duplikate gefiltert werden, sollten es 132 sein.
Ausgabe in Form von "iraq->vend\n"

mxf: Perl

perl -nle'$w{$r=$_=lc}++;y&a-z&n-za-m&;$w{$_}&&print"$r->$_"' /usr/share/dict/web2

50 Zeichen :)

urs: Perl

perl -nle'($u=$a{$i=$_=lc})&&print"$_->$u";y;a-z;n-za-m;;$a{$_}=$i' /usr/share/dict/web2

56+2 Zeichen

Zweite Einsendung: Klein, aber saulahm

perl -nle'$a{`echo -n $_|rot13`}=$_;print"$_->$a{$_}"if$a{$_}' /usr/share/dict/web2

51+2 Zeichen

PhilFry: Ruby

ruby -nle'y||={};$_.downcase!;y[$_]=0;r=$_.tr("a-z","n-za-m");y[r]&&(p $_+"->"+r)' < /usr/share/dict/web2

71 Zeichen

Ch3ka: php

<?$f=file($argv[1]);while($a[]=strtolower(next($f))){}while($b[]=str_rot13(next($a))){$c=end($b);if(in_array($c,$a))echo$c;}?>

122 Chrs

Kungi: Python

import sys
e=dict([(a,0)for a in open(sys.argv[1]).read().lower().split()])
for w in e:
 b=w.encode('rot13')
 if b in e:
  print w+" -> "+b
kungi@BeerBook: wc golf.py                                                                                                                  
      6      19     140 golf.py

k-zed: common lisp

(with-open-file (s "/usr/share/dict/web2")
  (let ((d (make-hash-table :test #'equal)))
    (loop for l = (read-line s nil) until (not l)
          do (setf (gethash (string-downcase l) d) t))
    (maphash
      (lambda (k v)
        (let ((p (map 'string (lambda (c) (code-char (+ (mod (- (char-code c) 84) 26) 97))) k)))
          (when (gethash p d) (format t "~A -> ~A~%" k p)))) d)))

CentronX: eicar & ein Inder

Man lasse einen Inder das ganze in eicar eintippen und dann vergleichen.

Sack-C-ment: C natürlich

#include <stdio.h>
#include <stdlib.h>
#include <search.h>

int main() {
	FILE *fd = fopen("/tmp/web2", "r"); char *b = malloc(234937 * 26); int c = 0; ENTRY e,*d; hcreate(234937);
	while (fgets(b+(26*c++), 26, fd)) { char *r=strdup(b+(26*(c-1))); e.key=r; while (*(++r) != '\0' && *r != '\n') *r = (*r+13 > 'z' ? *r-13 : *r+13); e.data = b+(26*(c-1)); hsearch(e, ENTER); }
	for (c = 0; c < 234937; c++) { e.key = b+(26*c); if (d=hsearch(e, FIND)) printf("print it! %s / %s\n", d->data, d->key); }
}

Compile / Setup:

sort /usr/share/dict/web2 /tmp/web2
gcc -o golf golf.c && ./golf

Exakt 500 Zeichen