Codegolf: Difference between revisions

From NoName e.V.
Jump to navigation Jump to search
Line 8: Line 8:


==== [[User:PhilFry|PhilFry]]: Ruby ====
==== [[User:PhilFry|PhilFry]]: Ruby ====
  ruby -e'words={};IO.readlines(ARGV[0]).each{|w|words[w.downcase.chomp]=true};words.each_key{|w|r=w.tr("a-z","n-za-m");puts w+"->"+r if words[r]}' /usr/share/dict/web2  
  ruby -e'w=readlines.map{|l|l.downcase};w.each{|l|r=l.tr("a-z","n-za-m");p l+"->"+r if w.include? r}' < /usr/share/dict/web2
 
136 Zeichen [[http://phil.idlecrew.de/rot13.txt Ausgabe]]
91 Zeichen
 
real    0m9.114s
user    0m5.692s
sys    0m0.421s


==== Ch3ka: php ====
==== Ch3ka: php ====

Revision as of 11:36, 18 September 2007

Challenge #1

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

mxf: Perl

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

63+2 Zeichen

PhilFry: Ruby

ruby -e'w=readlines.map{|l|l.downcase};w.each{|l|r=l.tr("a-z","n-za-m");p l+"->"+r if w.include? r}' < /usr/share/dict/web2

91 Zeichen

Ch3ka: php

<?$a=file('/usr/share/dict/web2');while($b[]=strtolower(str_rot13(next($a)))){}foreach($a as $c)if(in_array(strtolower($c),$b))echo $c;?>
ch3ka@bihatsch: wc rot13test.php                                              
 1   4 138 rot13test.php

v2:

<?$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={};a=open(sys.argv[1]).read().lower().split()
for w in a:e[w]=""
for w in a:
 b=w.encode('rot13')
 if e.has_key(b):e[b]=w
for a,b in e.iteritems():
 if b:print a+" -> "+b
kungi@BeerBook: wc golf2.py
       8      23     184 golf2.py