From: Software Scavenger
Subject: Roman numerals
Date: 
Message-ID: <a6789134.0112301121.124f6ee3@posting.google.com>
Re the recent thread on roman numerals:  Just for fun, here's a
short obfuscated version of roman.  You invoke it with a string,
e.g. (roman "iv") and it gives the number in decimal, or nil if
it's not valid roman.  E.g. "XXXX" is not valid roman because it
should be "XL".  There is no limit to the number of "M"s in this
version because that would just be an arbitrary limit on the size
of the number.  Also zero is allowed by simply giving it an empty
string, which is what the Romans used for zero.

(defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
  n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
  (length a)))(j 1000)(e(loop as i below j collect (m i)))
  (b(position a e :test 'equalp)))(and b(+(* k j)b)))))

From: Thomas F. Burdick
Subject: Re: Roman numerals
Date: 
Message-ID: <xcvitao31ha.fsf@apocalypse.OCF.Berkeley.EDU>
··········@mailandnews.com (Software Scavenger) writes:

> Re the recent thread on roman numerals:  Just for fun, here's a
> short obfuscated version of roman.  You invoke it with a string,
> e.g. (roman "iv") and it gives the number in decimal, or nil if
> it's not valid roman.  E.g. "XXXX" is not valid roman because it
> should be "XL".  There is no limit to the number of "M"s in this
> version because that would just be an arbitrary limit on the size
> of the number.  Also zero is allowed by simply giving it an empty
> string, which is what the Romans used for zero.
> 
> (defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
>   n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
>   (length a)))(j 1000)(e(loop as i below j collect (m i)))
>   (b(position a e :test 'equalp)))(and b(+(* k j)b)))))

An obfuscation tip: although misleading indentation can be good in
Lisp, don't forget that we all have pprint handy.  Which makes
removing whitespace pointless:

  * (pprint '(defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
      n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
      (length a)))(j 1000)(e(loop as i below j collect (m i)))
      (b(position a e :test 'equalp)))(and b(+(* k j)b))))))
  (defun roman (s)
    (flet ((m (n)
             (if (= 0 n) "" (format nil ··@R" n))))
      (let* ((a (string-left-trim "mM" s))
             (k (- (length s) (length a)))
             (j 1000)
             (e (loop as i below j collect (m i)))
             (b (position a e :test 'equalp)))
        (and b (+ (* k j) b)))))

Now, although those aren't the most descriptive names for variables,
it's not very difficult to figure out what's going on.  Convoluted
program logic tends to work better ;)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Dorai Sitaram
Subject: Re: Roman numerals
Date: 
Message-ID: <a0q8nb$ddh$1@news.gte.com>
In article <···············@apocalypse.OCF.Berkeley.EDU>,
Thomas F. Burdick <···@apocalypse.OCF.Berkeley.EDU> wrote:
>··········@mailandnews.com (Software Scavenger) writes:
>
>> Re the recent thread on roman numerals:  Just for fun, here's a
>> short obfuscated version of roman. ... 
>> 
>> (defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
>>   n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
>>   (length a)))(j 1000)(e(loop as i below j collect (m i)))
>>   (b(position a e :test 'equalp)))(and b(+(* k j)b)))))
>
>An obfuscation tip: although misleading indentation can be good in
>Lisp, don't forget that we all have pprint handy.  Which makes
>removing whitespace pointless: ...
>
>Now, although those aren't the most descriptive names for variables,
>it's not very difficult to figure out what's going on.  Convoluted
>program logic tends to work better ;)

I thought the obfuscation lay in the use of LOOP...

--d
From: Thomas F. Burdick
Subject: Re: Roman numerals
Date: 
Message-ID: <xcv4rm72ql8.fsf@apocalypse.OCF.Berkeley.EDU>
····@goldshoe.gte.com (Dorai Sitaram) writes:

> In article <···············@apocalypse.OCF.Berkeley.EDU>,
> Thomas F. Burdick <···@apocalypse.OCF.Berkeley.EDU> wrote:
> >··········@mailandnews.com (Software Scavenger) writes:
> >
> >> Re the recent thread on roman numerals:  Just for fun, here's a
> >> short obfuscated version of roman. ... 
> >> 
> >> (defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
> >>   n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
> >>   (length a)))(j 1000)(e(loop as i below j collect (m i)))
> >>   (b(position a e :test 'equalp)))(and b(+(* k j)b)))))
> >
> >An obfuscation tip: although misleading indentation can be good in
> >Lisp, don't forget that we all have pprint handy.  Which makes
> >removing whitespace pointless: ...
> >
> >Now, although those aren't the most descriptive names for variables,
> >it's not very difficult to figure out what's going on.  Convoluted
> >program logic tends to work better ;)
> 
> I thought the obfuscation lay in the use of LOOP...

My bad, I guess that was the obfuscated version of:

  (defun roman(s)(flet((m(n)(if(= 0 n)""(format nil ··@R"
    n))))(let*((a(string-left-trim "mM" s))(k(-(length s)
    (length a)))(j 1000)(f(lambda(f i acc)(if (< i j)(funcall
    f f (1+ i) (cons(m i)acc))(reverse acc))))(e(funcall f f 0
    ()))(b(position a e :test 'equalp)))(and b(+(* k j)b)))))

:)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'