t-iaind@microsoft.UUCP (Iain Davidson) (04/03/89)
(This is my first BIG post, so if you want to flame, flame low and send away)
For those still silly over the LAST puzzle/challange.... here's another one.
Puzzle:
Write a "simple" program to convert rec.humor (rot13) jokes to
a output readable by human eyes...
Simple rules:
1) It works.
2) I can understand it.
3) Sources in "C", Pascal, MOD-2, Pilot, or csh-source
format are acceptable.
Two catagories.
a) fastest
b) smallest (least # of characters not including standard_IO includes or
main(arg,arg) {} code, and ignoring white space '/n', <SPACE>
(CR's,LF's,etc) for readablity.
Two levels of difficulty:
1) using builtin functions of a OS i.e. ">" "<" for UNIX
2) using standard file operations of open/close.
Here's an example
( not working and NOT tested, only by my limited knowledge of c )
main()
{
char c;
while((c=getchar()!=EOF)
if( (('a' < c) && ('z' > c)) || (('A' < c) && ('Z' > c)) ) {
c=lower(c);
putchar( (c>'m' : c-13 ? c+13) );
}
}
(I'll summurize and post results..., good luck and may the gods go with you...)
Iain Davidson, formally of (Bellingham, WA)'s BelAmi! Fame
UUCP: {uucp|uw-beaver}!microsof!t-iaind (How did he move that "t" ???)
BITNET: microsof!t-iaind@beaver.cs.washington.edu
for really smart mailers: t-iaind@microsoft.BITNET or .CSNET or .UUCP
********** Disclaimer: *********
My employer and fellow employees will (have, has) disclaim anything I say
past, future, or present...... so there !!!!.... :P
-----------------------------------------------------------------kevin@uts.amdahl.com (Kevin Clague) (04/03/89)
In article <1210@microsoft.UUCP> t-iaind@microsoft.UUCP (Iain Davidson) writes: >(This is my first BIG post, so if you want to flame, flame low and send away) > > For those still silly over the LAST puzzle/challange.... here's another one. Please DO NOT post replies to this in comp.sys.amiga.tech. Try comp.sys.amiga if you must. -- UUCP: kevin@uts.amdahl.com or: {sun,decwrl,hplabs,pyramid,seismo,oliveb}!amdahl!kevin DDD: 408-737-5481 USPS: Amdahl Corp. M/S 249, 1250 E. Arques Av, Sunnyvale, CA 94086 [ Any thoughts or opinions which may or may not have been expressed ] [ herein are my own. They are not necessarily those of my employer. ]
rabaeza@watdragon.waterloo.edu (Ricardo A. Baeza-Yates) (04/04/89)
In article <1210@microsoft.UUCP> t-iaind@microsoft.UUCP (Iain Davidson) writes: >(This is my first BIG post, so if you want to flame, flame low and send away) > > For those still silly over the LAST puzzle/challange.... here's another one. #include <stdio.h> #include <ctype.h> main() { int c; for( ;(c=getchar())!=EOF; putchar(c)) if( isalpha(c) ) c = (lower(c)>'m') : c-13 ? c+13); } -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rabaeza@watmum.waterloo.{edu,cdn} 519-885-1211 x3497 Ricardo Baeza-Yates rabaeza@watmum.uwaterloo.ca CS Dept., U. Waterloo uunet!watmath!watmum!rabaeza Waterloo, Ont. N2L3G1
edw@pinot.zehntel.com (Ed Wright) (04/06/89)
In article <1210@microsoft.UUCP> t-iaind@microsoft.UUCP (Iain Davidson) writes: >(This is my first BIG post, so if you want to flame, flame low and send away) Noooooo Problem > For those still silly over the LAST puzzle/challange.... here's another one. > >Puzzle: > Write a "simple" program to convert rec.humor (rot13) jokes to > a output readable by human eyes... A new challange ! Thank god >Simple rules: > 1) It works. > 2) I can understand it. No fair imposing unrealistic restrictions > 3) Sources in "C", Pascal, MOD-2, Pilot, or csh-source > format are acceptable. > >UUCP: {uucp|uw-beaver}!microsof!t-iaind (How did he move that "t" ???) >BITNET: microsof!t-iaind@beaver.cs.washington.edu :-) Here are some of my favorites man tr man mail man ceasar talk root mail root subject: How do I do this ? and of course the ever popular old favorite :-) /bin/rm -F -r * should fix most rotation problems in your current working directory. I suppose there is always... naw..... not reading "the book" I think the best reply to one of these was the guy who a few months back posted a loverly csh script that was rot 13. :-) NOw remember the tricks you have seen here today were done by skilled proffessionals who do them every day. DO NOT TRY these tricks at home without close parental supervision. Ed Wright KA9AHQ sun or ucbvax or varian ! zehntel!edw edw@zehntel.COM
reeder@reed.UUCP (Doug Reeder) (04/06/89)
program decode(input, output, code, plain);
{decode cypher}
const
NumTestLines = 10;
type
lowercase = 'a' ..'z';
var
coding : array[lowercase] of lowercase;
LetterSet, LowerCaseSet : set of char;
code, plain : text;
print : boolean;
function lookup(c : char) : char;
begin
if c in LetterSet then begin
if c in LowerCaseSet then
lookup := coding[c]
else
lookup := coding[chr(ord(c)+32)];
end
else
lookup := c;
end;
procedure WriteCoding(var tf : text);
var ch : char;
begin
writeln(tf);
for ch := 'a' to 'z' do write(tf,ch);
writeln(tf);
for ch := 'a' to 'z' do write(tf,coding[ch]);
writeln(tf);
end;
procedure TryRotations(var print : boolean);
var
ch,response : char;
rotation,lines : integer;
continue : boolean;
begin
rotation := 1;
print := false;
continue := true;
repeat
for ch := 'a' to 'z' do
coding[ch] := chr(((ord(ch)-ord('a') + rotation) mod 26) + ord('a'));
lines :=0;
reset(code);
page(output);
repeat
if eoln(code) then begin
writeln;
lines := lines + 1;
end
else
write(lookup(code^));
get(code);
until (lines = NumTestLines)or eof(code);
write('Okay? [y,n,q] '); readln(response);
if response = 'y' then begin
continue := false;
print := true;
WriteCoding(output);
end;
if response = 'q' then begin continue := false; print := false; end;
rotation := rotation +1;
until (continue = false) or (rotation = 26);
end;
procedure PrintOut;
begin
reset(code);
rewrite(plain);
repeat
if eoln(code) then
writeln(plain)
else
write(plain,lookup(code^));
get(code);
until eof(code);
end;
procedure setup;
begin
LetterSet := ['a'..'z','A'..'Z'];
LowerCaseSet := ['a'..'z'];
end;
begin {decode}
setup;
TryRotations(print);
if print then PrintOut;
end.
--
Doug Reeder USENET: ...!tektronix!reed!reeder
Institute of Knowledge BITNET: reeder@reed.BITNET
Jinx from ARPA: tektronix!reed!reeder@berkeley.EDU
reeder@knowledge.JINX Box 971 Reed College,Portland,OR 97202kyle@ritcsh.UUCP (Kyle Saunders) (04/07/89)
In article <1210@microsoft.UUCP>, t-iaind@microsoft.UUCP (Iain Davidson) writes: > (This is my first BIG post, so if you want to flame, flame low and send away) > > For those still silly over the LAST puzzle/challange.... here's another one. > > Puzzle: > Write a "simple" program to convert rec.humor (rot13) jokes to > a output readable by human eyes... > C version: (uses redirection/pipes) #include <studio.h> main() { char c; while ((c = getchar()) != EOF) { if ((c >= 'A') && (c <= 'Z')) c = ((c-'A'+13) % 26) + 'A'; else if ((c >= 'a') && (c <= 'z')) c = ((c-'a'+13) % 26) + 'a'; putchar(c); } } sh version: (also uses redirection/pipes) #rot13.sh #!/bin/sh tr A-MN-Za-mn-z N-ZA-Mn-za-m - Kyle Saunders Computer Science House @ Rochester Institute of Technology {known.galaxy}!ccicpg!cci632!ritcsh!kyle or kyle%ritcsh@rit.RIT.EDU
850347s@aucs.UUCP (Hume Smith) (04/07/89)
reeder@reed.UUCP (Doug Reeder) almost, but not quite, wrote }- program decode(input, output, code, plain); }- [ ... ] }- end. exactly why i hate pascal - a hundred lines of illegibility instead of the 2 or 3 you'd have in C. i wonder if i can do this in Lisp... -- Hume Smith Wolfville Nova Scotia BITNET 850347s@Acadia Internet 850347s%Acadia.BITNET@CUNYVM.CUNY.EDU UUCP {uunet|watmath|utai|garfield}!dalcs!aucs!850347s
850347s@aucs.UUCP (Hume Smith) (04/08/89)
850347s@aucs.UUCP (Hume Smith) almost, but not quite, wrote }- exactly why i hate pascal - a hundred lines of illegibility instead of the }- 2 or 3 you'd have in C. }- }- i wonder if i can do this in Lisp... read that carefully, i do mean the 2 or 3 lines of illegibilty :-) this runs under franz lisp... i recommend compiling it though. Usage: (rot13 t_filename) (def alpha<= (lambda (&rest x) (if (or (null x) (null (cdr x))) t (and (or(eq (car x) (cadr x)) (alphalessp (car x) (cadr x))) (apply 'alpha<= (cdr x)))))) (def rot13 (lambda (file) ((lambda (port) (do ((X)) ((null (setq X (readc port)))) (princ (cond ((or (alpha<= 'a X 'm) (alpha<= 'A X 'M)) (ascii (+ (getcharn X 1) 13))) ((or (alpha<= 'n X 'z) (alpha<= 'N X 'Z)) (ascii (- (getcharn X 1) 13))) (t X)))) (close port)) (infile file)))) -- now: HAS THIS BLEEDIN' ROT13 NONSENSE GONE ON LONG ENOUGH? -- Hume Smith Wolfville Nova Scotia BITNET 850347s@Acadia Internet 850347s%Acadia.BITNET@CUNYVM.CUNY.EDU UUCP {uunet|watmath|utai|garfield}!dalcs!aucs!850347s
rr@sun2.cs.uh.edu (Ravindran Ramachandran) (04/08/89)
In article <1744@aucs.UUCP> 850347s@aucs.UUCP (Hume Smith) writes: >reeder@reed.UUCP (Doug Reeder) almost, but not quite, wrote >}- program decode(input, output, code, plain); >}- [ ... ] >}- end. > >exactly why i hate pascal - a hundred lines of illegibility instead of the >2 or 3 you'd have in C. > >i wonder if i can do this in Lisp... Write a parallel program to implement this: Use 27 nodes. Each node is sent the corresponding character, and it outputs the ROT13ed character. Have a `manager' node to collect all the characters back together and output it. -- Ravi. Disclaimer: My computer typed this in when I was not looking.