From: Kenneth Tilton
Subject: Live from the trenches, Nooby Exercise #17, aka There' Gotta Be A Better Way #32
Date: 
Message-ID: <49658465$0$20290$607ed4bc@cv.net>
The spec and final exam:
   (and (= 11000000 (u-store 11220000))
     (= 11220000 (u-store 11223300))
     (= 11223300 (u-store 11223344))
     (null (u-store 11000000))))

...because the UNSPSC ( http://www.unspsc.org/ ) works like this:

An eight-digit code denotes a four-level tree, each two digits being the 
key to a node: AA BB CC DD where DD is a subnode under the CC subnode of 
(you get it). "00" signifies a root subnode, so:

11223344 has no subnodes;
11223300 is the parent category (useful because it gets its own 
description);
11220044 is impossible; and
there is no 00000000.

We will assume the input code is valid.

My first effort was just awful, my second probably could be better but 
this is work stuff so time to move on. These will appear in a followup 
labelled as "spoiler".

hth, kt

From: Kenneth Tilton
Subject: SPOILER [was Re: Live from the trenches, Nooby Exercise #17, aka There' Gotta Be A Better Way #32]
Date: 
Message-ID: <49658807$0$20300$607ed4bc@cv.net>
Kenneth Tilton wrote:
> The spec and final exam:
>   (and (= 11000000 (u-store 11220000))
>     (= 11220000 (u-store 11223300))
>     (= 11223300 (u-store 11223344))
>     (null (u-store 11000000))))
> 
> ...because the UNSPSC ( http://www.unspsc.org/ ) works like this:
> 
> An eight-digit code denotes a four-level tree, each two digits being the 
> key to a node: AA BB CC DD where DD is a subnode under the CC subnode of 
> (you get it). "00" signifies a root subnode, so:

That confuses even me. Let's say trailing "00" chunks denote a group. 
ie, they could have made "112233" the parent of "11223344" but maybe 
they were thinking about numeric sorts/groups more than strings. Makes 
sense.

> 
> 11223344 has no subnodes;
> 11223300 is the parent category (useful because it gets its own 
> description);
> 11220044 is impossible; and
> there is no 00000000.
> 
> We will assume the input code is valid.
> 
> My first effort was just awful, my second probably could be better but 
> this is work stuff so time to move on. These will appear in a followup 
> labelled as "spoiler".
> 
> hth, kt

My first effort (and this was string-based, I forgot, so the test is 
different and incomplete (fails on "11000000" not having a parent)):

(defun u-store-eww (x)
   (loop with parent = 2
       for level upfrom 1 to 3
       for seg = (subseq x (* 2 level) (+ 2 (* 2 level)))
       when (string= seg "00")
       do (setf parent (- level 2))
         (loop-finish)
       finally
         (return (concatenate 'string
                   (subseq x 0 (+ 2 (* 2 parent)))
                   (make-string (* 2 (- 3 parent)) :initial-element #\0)))))

(and (string= "11000000" (u-store-eww "11220000"))
   (string= "11220000" (u-store-eww "11223300"))
   (string= "11223300" (u-store-eww "11223344")))

My effort:

(labels ((u-store (k &key (key k))
            (when (> k 100)
              (if (plusp (mod k 100))
                  (* (floor k 100)
                    (expt 10 (- 9 (floor (log k 10)))))
                (u-store (floor k 100) :key key)))))
   (and (= 11000000 (u-store 11220000))
     (= 11220000 (u-store 11223300))
     (= 11223300 (u-store 11223344))
     (null (u-store 11000000))))

I hate the zero-filling computation.

kt
From: D Herring
Subject: Re: Live from the trenches, Nooby Exercise #17, aka There' Gotta Be A Better Way #32
Date: 
Message-ID: <496589e8$0$15636$6e1ede2f@read.cnntp.org>
Kenneth Tilton wrote:
> The spec and final exam:
>   (and (= 11000000 (u-store 11220000))
>     (= 11220000 (u-store 11223300))
>     (= 11223300 (u-store 11223344))
>     (null (u-store 11000000))))
> 
> ...because the UNSPSC ( http://www.unspsc.org/ ) works like this:


You're not making this up...  It really exists.?.

Wow.

Now I don't know which is worse:  the "unspec", or EUROCONTROL's 
Asterix data format.

- Daniel
From: Kenneth Tilton
Subject: Re: Live from the trenches, Nooby Exercise #17, aka There' Gotta Be A Better Way #32
Date: 
Message-ID: <4965922b$0$20301$607ed4bc@cv.net>
D Herring wrote:
> Kenneth Tilton wrote:
>> The spec and final exam:
>>   (and (= 11000000 (u-store 11220000))
>>     (= 11220000 (u-store 11223300))
>>     (= 11223300 (u-store 11223344))
>>     (null (u-store 11000000))))
>>
>> ...because the UNSPSC ( http://www.unspsc.org/ ) works like this:
> 
> 
> You're not making this up...  It really exists.?.

Annual membership for an individual just $300! Corporate global $6000.

> 
> Wow.

It gets better. Periodically they move all the codes around to improve 
the semantics.

Fun note: the first category "10" is all about animals and pets. I 
wonder if it all started in-house at a ... hey, is that why we say "eat 
your own dog food"?


kt