TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: myloveflyer on May 30, 2011, 04:54:39 AM

Title: How grouping and Conversion
Post by: myloveflyer on May 30, 2011, 04:54:39 AM
For example:
"165478952"
Results: "A" "/" "Y" "4"
Title: Re: How grouping and Conversion
Post by: Coder on May 30, 2011, 05:12:13 AM
Check this .  :-)

Code: [Select]
(vl-list->string '(65 47 89 52))
Title: Re: How grouping and Conversion
Post by: myloveflyer on May 30, 2011, 05:45:36 AM
(defun c:test()
(setq a (getstring "\nEnter numbers:"))
(setq b (vl-list->string ' a))
(princ)
)

Finally, the error
How to make a transition to form groups and then conversion
Title: Re: How grouping and Conversion
Post by: gile on May 30, 2011, 06:23:11 AM
Not certain to understand the task, but this works with the example.

(foo "165478952") returns ("A" "/" "Y" "4")

Code: [Select]
(defun foo (str / num char lst)
  (if (numberp (setq num (read str)))
    (while (< 9 (setq char (rem num 100)))
      (setq num (/ num 100)
    lst (cons (chr char) lst)
      )
    )
  )
)
Title: Re: How grouping and Conversion
Post by: Coder on May 30, 2011, 07:20:25 AM
Like this ....  :-)

Code: [Select]
(defun c:test (/ ss)
  (if (setq ss (getint "\n Enter Number (ascii) :"))
    (print (chr ss))
    )
  (princ)
  )
Title: Re: How grouping and Conversion
Post by: Lee Mac on May 30, 2011, 07:52:12 AM
I think this task needs more clarification, but perhaps:

Code: [Select]
(defun num->str ( num )
  (cond
    ( (< 31 num 100) (list (chr num)))
    ( (< 31 num) (append (num->str (/ num 100)) (num->str (rem num 100))))
  )
)

Code: [Select]
_$ (num->str 165478952)
("A" "/" "Y" "4")
Title: Re: How grouping and Conversion
Post by: myloveflyer on May 31, 2011, 09:10:10 PM
Like this ....  :-)

Code: [Select]
(defun c:test (/ ss)
  (if (setq ss (getint "\n Enter Number (ascii) :"))
    (print (chr ss))
    )
  (princ)
  )
Thanks coder,but "enter number"requires an integer between -32768 and 32767.My version is 04 CAD

Not certain to understand the task, but this works with the example.

(foo "165478952") returns ("A" "/" "Y" "4")

Code: [Select]
(defun foo (str / num char lst)
  (if (numberp (setq num (read str)))
    (while (< 9 (setq char (rem num 100)))
      (setq num (/ num 100)
   lst (cons (chr char) lst)
      )
    )
  )
)
thanks,gile,When the input number is 11, when an error。
thanks,LEE,As your programs and gile error
I may be the expression of this program is not clear, I mean that when I enter the number as 11, when, for example: 16738883211, rounding first need to form a list ("67" "38" "88" "32" "11"), the group then identified the corresponding code in general is to enter the figures are rounded down first, and then behind the two figures as a whole, the basic input of the number of digits is 9 or 11, Thank you for your help, hope that help me look,

Title: Re: How grouping and Conversion
Post by: Lee Mac on May 31, 2011, 09:23:42 PM
Your figure of 16738883211 exceeds the signed integer limit for 32-bit systems (2147483647 = ((2^32)/2)-1) and is hence converted to a real in LISP.
Title: Re: How grouping and Conversion
Post by: myloveflyer on May 31, 2011, 09:41:40 PM
LEE, you mean 11 out of 32-bit systems has been limited, indeed, as you said the program will error, whether to enter the number from 11 into 9 digits, so I would like to no error Right?
Title: Re: How grouping and Conversion
Post by: Lee Mac on May 31, 2011, 09:53:52 PM
LEE, you mean 11 out of 32-bit systems has been limited, indeed, as you said the program will error, whether to enter the number from 11 into 9 digits, so I would like to no error Right?

Use this instead perhaps:

Code: [Select]
(defun num->str ( num )
  (cond
    ( (< 31 num 100) (list (chr (fix num))))
    ( (< 31 num) (append (num->str (/ num 100)) (num->str (rem num 100))))
  )
)

What are you trying to achieve?
Title: Re: How grouping and Conversion
Post by: myloveflyer on May 31, 2011, 10:12:33 PM
(foo "165478952") returns ("A" "/" "Y" "4")

(num->str 165478952) returns ("A" "/" "Y" "4")

I need 11-bit digital input when you are as follows:
(foo "16547895233") returns ("A" "/" "Y" "4" "!")
(num->str 16547895233) returns ("A" "/" "Y" "4" "!")

Title: Re: How grouping and Conversion
Post by: Jeff H on June 01, 2011, 08:41:52 PM
Would keeping up with a count variable work by taking the substring of count + 2?

I not fimilar enough with lisp but get sslen and while count < slen
do your magic here
Title: Re: How grouping and Conversion
Post by: Lee Mac on June 02, 2011, 09:38:12 AM
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
)
Title: Re: How grouping and Conversion
Post by: Jeff H on June 02, 2011, 09:55:51 AM
Nice Lee,

I played with it for a little bit and could'nt get it to work.
Title: Re: How grouping and Conversion
Post by: MP on June 02, 2011, 09:56:58 AM
I seem to be missing a couple things here ...


Mommy I need a coffee. Back to you Jim.
Title: Re: How grouping and Conversion
Post by: Lee Mac on June 02, 2011, 09:59:38 AM
  • 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?

Oh exactly - I'm with you on all three points. I'm just going with the info given  :|
Title: Re: How grouping and Conversion
Post by: MP on June 02, 2011, 10:04:46 AM
oh (http://www.theswamp.org/screens/mp/oh.gif)

Can I get you a coffee too?

:D
Title: Re: How grouping and Conversion
Post by: gile on June 02, 2011, 10:06:07 AM
I completely agree Michael.
Rather than a "challenge" this thread appears to me as an enigma.
Title: Re: How grouping and Conversion
Post by: MP on June 02, 2011, 10:07:41 AM
ok, 3 coffee to go  :-D
Title: Re: How grouping and Conversion
Post by: Lee Mac on June 02, 2011, 10:15:37 AM
I'll have an espresso 8-)
Title: Re: How grouping and Conversion
Post by: MP on June 02, 2011, 10:17:49 AM
(http://dl.dropbox.com/u/10117392/happy_coffee.png)
Title: Re: How grouping and Conversion
Post by: Lee Mac on June 02, 2011, 10:20:14 AM
 :lol: Cheers  :lol:
Title: Re: How grouping and Conversion
Post by: myloveflyer on June 03, 2011, 09:35:14 PM
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
)

Nice,LEE,But for less than 31 if there is no corresponding data in ASCII, for example:
Code: [Select]
(decode "105122231")
("\005" "\014" "\026" "\037")
Give each person a cup of coffee  :laugh:
Title: Re: How grouping and Conversion
Post by: Jeff H on June 03, 2011, 09:48:34 PM
http://www.asciitable.com/
using that site

How about this.

2 == Start of Text
3 == End of Text

And in between must at least equal 32 and can equal up to 126.

So for example:

("2457646124553")

2 starts
45
76
46
124 So when a 1 appears as example above it cannot be followed by a number higher than 2 and if 2 the next number must be 6 or less.
55
3 ends
Title: Re: How grouping and Conversion
Post by: Lee Mac on June 03, 2011, 09:56:45 PM
/giveup
Title: Re: How grouping and Conversion
Post by: myloveflyer on June 03, 2011, 10:24:53 PM
Jeff H, difficult for you than I will.
 LEE, thank you, now my needs have been met, the conversion of data can be converted over to go back? With vl-list-> string?

Title: Re: How grouping and Conversion
Post by: Jeff H on June 04, 2011, 12:18:32 AM
/giveup
If me

Never

Been 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
Title: Re: How grouping and Conversion
Post by: myloveflyer on June 06, 2011, 08:49:21 PM
/giveup
If me

Never

Been 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

Jeff ,Hope that the healthy growth of your son, your perseverance worthy of our study.
Title: Re: How grouping and Conversion
Post by: Jeff H on June 06, 2011, 09:09:30 PM
Thanks mloveflyer,

I have messed with it a little and have not come up with anything useful.