Codegolf: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
=== Challenge #1 === | === Challenge #1 === | ||
<SdK> gibts wörter, die nach rot13 n anderes existierendes wort ergeben? | <SdK> gibts wörter, die nach rot13 n anderes existierendes wort ergeben? | ||
Testdatei: http://qu.cx/~mxf/web2.gz | |||
gepiped durch wc -l sollte 132 rausfallen | |||
==== mxf: Perl ==== | ==== mxf: Perl ==== |
Revision as of 15:25, 18 September 2007
Challenge #1
<SdK> gibts wörter, die nach rot13 n anderes existierendes wort ergeben?
Testdatei: http://qu.cx/~mxf/web2.gz gepiped durch wc -l sollte 132 rausfallen
mxf: Perl
perl -nle'$w{+lc}++}for(keys%w){$r=$_;y/a-z/n-za-m/;$w{$_}&&print"$r -> $_' /usr/share/dict/web2
65+2 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
PhilFry: Ruby
ruby -nle'y||={};y[$_.downcase!||$_]=0;r=$_.tr("a-z","n-za-m");y[r]&&(p $_+"->"+r)' < /usr/share/dict/web2
72 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)))