0 Members and 1 Guest are viewing this topic.
Is the original data correct? i.e. why the superfluous 1 prefix ("165478952")?What assurances does the coder have that ASCII values less than 10 or greater than 99 are not in the string? Subtitle: it would screw up the pairing.What is the context of the challenge?
Nice idea Jeff, how about this approach:Code: [Select](defun decode ( x / l ) (setq x (reverse (vl-string->list x))) (while (cadr x) (setq l (cons (chr (- (+ (car x) (* 10 (cadr x))) 528)) l) x (cddr x)) ) l)Code: [Select]_$ (decode "165478952")("A" "/" "Y" "4")Or, using substr (likely to be slower):Code: [Select](defun decode2 ( s / l x ) (repeat (/ (setq x (strlen s)) 2) (setq l (cons (chr (atoi (substr s (setq x (1- x))))) l) s (substr s 1 (setq x (1- x))) ) ) l)
(defun decode ( x / l ) (setq x (reverse (vl-string->list x))) (while (cadr x) (setq l (cons (chr (- (+ (car x) (* 10 (cadr x))) 528)) l) x (cddr x)) ) l)
_$ (decode "165478952")("A" "/" "Y" "4")
(defun decode2 ( s / l x ) (repeat (/ (setq x (strlen s)) 2) (setq l (cons (chr (atoi (substr s (setq x (1- x))))) l) s (substr s 1 (setq x (1- x))) ) ) l)
(decode "105122231")("\005" "\014" "\026" "\037")
/giveup
Quote from: Lee Mac on June 03, 2011, 09:56:45 PM/giveupIf meNeverBeen playing with my son and usually is asleep by now but poor guy just went downhill quick and fever shot up etc.... If you got a solution go ahead or I know you do I won't look until I fail a couple of times