[EMAIL PROTECTED] wrote:
> Hi,
> 
> I saw a perl script in USENET news that coded text to CW -alphabets,
> the author of script challenged others to do the same with a shorter
> program. I thought to do it in REBOL. Here it is, much shorter than
> the original perl -script, that was actually very badly written, but
> unfortunately a bit longer than the shortest (and very unreadable)
> perl script. This script is a bit broken (because I tried to take
> every byte off that I could). And almost unreadable. It is certainly
> not a good example how one should program in REBOL. I post it
> here just because there might be some interested in it. Here it comes
> (about 210 bytes :)
> 
> REBOL[]foreach c system/script/args[s: copy{ }x: index? 
> find{etianmsurwdkgohvf�l�pjbxcyzq�*54*3***2*******16*******7***8*90}c
> until[s:
> head insert s either odd? x["."]["-"](x: to-integer x - 1 / 2) = 0]prin
> s]

Interesting. :)

I invented the same program myself some years ago, and I have actually
ported it to Rebol as well!
I managed to make my version a couple of bytes shorter still by looking at
your version, and my version also handles spaces (which are represented as
an extra space). Other unknown characters also result in extra spaces.

Here's the version which does the same thing as yours (except it also
handles some extra chars, namely �, /, � and �):

REBOL[]m:{%etinamsdrgukwohblzfcp�vx�q�yj�56%7�%%8%/%%%%%94%%%%%�%3%%�2%10}
foreach c system/script/args[error? try[l: index? find m c until[prin
pick{-�}odd? l(l: l / 2)< 2]]prin{ }]

Now if that's not short enough, let's move the input to inside the program:
REBOL[]m:{%etinamsdrgukwohblzfcp�vx�q�yj�56%7�%%8%/%%%%%94%%%%%�%3%%�2%10}
foreach c ask{}[error? try[l: index? find m c until[prin pick{-�}odd? l(l: l
/
2)< 2]]prin{ }]

If we decide to skip the digits and non-english/german characters, it fits
in just two <80 char lines:
(this one also exits nicely :)

REBOL[]m:{%etinamsdrgukwohblzfcp�vx�q�yj}foreach c system/script/args[error?
try[l: index? find m c until[prin pick{-�}odd? l(l: l / 2)<
2]]prin{}]print{}q

Or for the ultra-short version:

REBOL[]m:{%etinamsdrgukwohblzfcp�vx�q�yj}foreach c ask{}[error? try[l:
index?
find m c until[prin pick{-�}odd? l(l: l / 2)< 2]]prin{}]

And finally a version which also takes some extra chars, namely :, ?, ", ',
-, ., ( and the comma. There is only one "parenthesis" specified. Also,
these versions use "�" in the position which is specified as "Ch".

REBOL[]m:{%etinamsdrgukwohblzfcp�vx�q�yj�56%7�%%8%/%%%%%94%%%%%�%3%%�2%10%%%%%%
:%%%%?%%%%%"%%%%%%%%%%%'%%-%%%%%%%%.%%(%%%%%,}foreach c system/script/args[
error? try[l: index? find m c until[prin pick{-�}odd? l(l: l / 2)<
2]]prin{}]

(on some system this may fail because the string includes the linebreak,
which is two chars on some systems and one char on others. If it fails,
delete the last "%" on the first line)


-- 
  /Johan R�nnblom, Team Amiga

Reply via email to