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
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 97202wechsler@leah.Albany.Edu (Steve Wechsler) (04/07/89)
Please remove rec.humor from this thread! Thanks for your cooperation... -- Steve Wechsler | Internet: wechsler@leah.albany.edu Bitnet: consp01@bingvaxa | consp01@bingvaxu.cc.binghamton.edu Sometimes, late at night, someone gets the urge to pet a small furry animal. That's where I come in. My name's Friday. I carry a badger.
kyle@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
dgr0093%ritcv@cs.rit.edu (340 Ok) (04/07/89)
I wasn't going to post this, but decoding rot13 text is much easier than that
last program would indicate. I wrote this a few months ago, and it's a full
text filter, so you can pipe things at it as well as calling it with a
filename to translate. I find the "text filter guts" very useful for building
other simple text filters.
Of course, "rot13 file | rot13" just types out the original file, so you can be
silly with it, too, if you're so inclined. :)
program rot13;
type
line = string[120];
var
buf: line;
function rot13 (inp:line): line;
var
count: integer;
begin
for count := 1 to length(inp) do
case inp[count] of
'A'..'M', 'a'..'m': inp[count] := chr(ord(inp[count])+13);
'N'..'Z', 'n'..'z': inp[count] := chr(ord(inp[count])-13)
end;
rot13 := inp
end;
begin
if paramcount > 0 then begin
close (input);
assign (input, paramstr(1));
{$I-} reset (input); {$I+}
if ioresult <> 0 then begin
writeln ('Error opening ',paramstr(1), ' as input: aborting');
halt
end
end;
repeat
readln (buf);
writeln (rot13(buf))
until eof (input)
end.
-------------------------------------------------------------------
Dave Rutherford Michelangelo H. Jones DGR0093@RITVAX.BITNET
-------------------------------------------------------------------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.
reeder@reed.UUCP (Doug Reeder) (04/09/89)
In article <1744@aucs.UUCP> 850347s@aucs.UUCP (Hume Smith) writes about my pascal program: > >exactly why i hate pascal - a hundred lines of illegibility instead of the >2 or 3 you'd have in C. Alert readers will have noticed that my program decodes from an unknown rotation to plain text, not merely from ROT13, and depends on no compiler specific features. -- 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 97202
crew@polya.Stanford.EDU (Roger Crew) (04/10/89)
In article <1751@aucs.UUCP> 850347s@aucs.UUCP (Hume Smith) writes: >In <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. > > read that carefully, i do mean the 2 or 3 lines of illegibilty :-) Three lines of illegibility? No problem... main(){ register b; while(~(b=getchar())) putchar(1+(('@'^--b&'_')<26?b^="\r\017\r\023\025\027\025\023\035\037\035\023\025"[b%32%13]:b)); } -- Roger Crew ``Beam Wesley into the sun!'' Usenet: {arpa gateways, decwrl, uunet, rutgers}!polya.stanford.edu!crew Internet: crew@polya.Stanford.EDU