it must do IO as well
<?php for($i=0;$i<strlen($_GET['chars']);$i++){$char=substr($_GET['chars'],$i,1);$ca=ord($char);echo((($ca>96&&$ca<123)||($ca>64&&$ca<91))?chr((($ca>96&&$ca<122)?(122-$ca>=13)?($ca+13):(97+(13-(123-$ca))):((90-$ca>=13)?($ca+13):(64+(13-(90-$ca)))))):$char);} ?>
http://www.sidoh.org/~sidoh/rot13.php?chars=hi2u
You can't use semicolons, it's no longer a single line! :P
Here's a real one-liner, no semicolons or nothing, handles upper/lower case and punctuation properly:
foreach(<>){foreach(split(//)) { print (((ord($_) > 0x40 && ord($_) < 0x5b) || (ord($_) > 0x60 && ord($_) < 0x7b)) ? chr(((ord($_) - (ord($_) < 0x61 ? 0x41 : 0x61) + 13) % 26) + (ord($_) < 0x61 ? 0x41 : 0x61)) : $_)}}
Quote from: iago on August 15, 2006, 04:58:17 PM
You can't use semicolons, it's no longer a single line! :P
Then replace $ca with ord(substr($_GET['chars'],$i,1)) and I win :P
Quote from: iago on August 15, 2006, 04:58:17 PM
Here's a real one-liner, no semicolons or nothing, handles upper/lower case and punctuation properly:
The one I did did that too...
Good job!
Next challenge: Write it in less than 25 characters.
Quote from: Sidoh on August 15, 2006, 05:11:21 PM
Then replace $ca with ord(substr($_GET['chars'],$i,1)) and I win :P
You lose! Using PHP is cheating anyways, you don't have to do I/O :(
Quote from: Sidoh on August 15, 2006, 05:11:21 PM
The one I did did that too...
I know, I was just saying.. :P
Quote from: Ender on August 15, 2006, 05:13:19 PM
Good job!
Next challenge: Write it in less than 25 characters.
Mmm, not likely, I doubt I could do less than about 150, including i/o...
Best I can do in Perl, without using CGI, is 73 chars, only works on uppercase/no punctuation:
foreach(<>){foreach(split(//)){$i=ord($_);print chr($i<110?$i+13:$i-13)}}
:(
Hehe, there's a trick to it. There's a very very quick way to do IO (both an input and an output) in perl (what may be two lines may count as one line, but usually one of the lines I am talking about is not considered a line).
include('a'); echo r($d);
I win.
lol no stop looking for workarounds you guys!
Plus, I was vague about what I meant by two lines. There's only one semi-colon (or line-terminating character excepting crlf).
EDIT: K, I'm just going to stop being ambiguous, sorry for being it before. The challenge is 25 characters or less excluding the #! shebang. It can be done in one line (excluding the shebang, and by line I mean a programming statement) but this is not a requirement (although there may be no two-line 25-char-satisfying solution to this). And any external sources or binaries that you use cannot assist you in doing the rot13.
exec('rot13');
I win.
Okay, here's the answer that involves 25 chars or less. Being only one line, we may as well run this one in interactive mode.
perl -p -e "tr/A-Za-z/N-ZA-Mn-za-m/;"
Cool eh? It uses transliterations instead of looping through every character in a string.
Edit: You'll never want to go to rot13.com again! =P
I was wondering if it could be done using tr///, but I didn't know how. Huh!
That whole line is 37 characters. Eh?
Newby, this is the code:
tr/A-Za-z/N-ZA-Mn-za-m/;
Put that in a file and perl -p it. Less than 25 characters.
I realize what the code is. But you gave that entire line like the line itself was the solution. :P
How about this shell script for the win?
tr A-Za-z N-ZA-Mn-za-m
Quotenewby@impaler:~/Downloads/vmware-server$ perl -p -e "tr/A-Za-z/N-ZA-Mn-za-m/;"
Testing!
Grfgvat!
newby@impaler:~/Downloads/vmware-server$ tr A-Za-z N-ZA-Mn-za-m
Testing!
Grfgvat!
Mine requires less resources I wager. :)
haha that's neat :D I didn't know there was a tr command.
I don't really care about the resources but it is less to type ^.^