Author Topic: How grouping and Conversion  (Read 6527 times)

0 Members and 1 Guest are viewing this topic.

myloveflyer

  • Newt
  • Posts: 152
How grouping and Conversion
« on: May 30, 2011, 04:54:39 AM »
For example:
"165478952"
Results: "A" "/" "Y" "4"
Never give up !

Coder

  • Swamp Rat
  • Posts: 827
Re: How grouping and Conversion
« Reply #1 on: May 30, 2011, 05:12:13 AM »
Check this .  :-)

Code: [Select]
(vl-list->string '(65 47 89 52))

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #2 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
Never give up !

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How grouping and Conversion
« Reply #3 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)
      )
    )
  )
)
« Last Edit: May 30, 2011, 07:23:27 AM by gile »
Speaking English as a French Frog

Coder

  • Swamp Rat
  • Posts: 827
Re: How grouping and Conversion
« Reply #4 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)
  )

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #5 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")

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #6 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,

Never give up !

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #7 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.
« Last Edit: May 31, 2011, 09:54:23 PM by Lee Mac »

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #8 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?
Never give up !

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #9 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?

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #10 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" "!")

Never give up !

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How grouping and Conversion
« Reply #11 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
« Last Edit: June 01, 2011, 08:55:02 PM by Jeff H »

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #12 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
)
« Last Edit: June 02, 2011, 10:19:19 AM by Lee Mac »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How grouping and Conversion
« Reply #13 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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How grouping and Conversion
« Reply #14 on: June 02, 2011, 09:56:58 AM »
I seem to be missing a couple things here ...

  • 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?

Mommy I need a coffee. Back to you Jim.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #15 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  :|

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How grouping and Conversion
« Reply #16 on: June 02, 2011, 10:04:46 AM »
oh

Can I get you a coffee too?

:D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How grouping and Conversion
« Reply #17 on: June 02, 2011, 10:06:07 AM »
I completely agree Michael.
Rather than a "challenge" this thread appears to me as an enigma.
Speaking English as a French Frog

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How grouping and Conversion
« Reply #18 on: June 02, 2011, 10:07:41 AM »
ok, 3 coffee to go  :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #19 on: June 02, 2011, 10:15:37 AM »
I'll have an espresso 8-)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How grouping and Conversion
« Reply #20 on: June 02, 2011, 10:17:49 AM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #21 on: June 02, 2011, 10:20:14 AM »
 :lol: Cheers  :lol:

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #22 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:
Never give up !

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How grouping and Conversion
« Reply #23 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

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: How grouping and Conversion
« Reply #24 on: June 03, 2011, 09:56:45 PM »
/giveup

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #25 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?

Never give up !

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How grouping and Conversion
« Reply #26 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

myloveflyer

  • Newt
  • Posts: 152
Re: How grouping and Conversion
« Reply #27 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.
Never give up !

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How grouping and Conversion
« Reply #28 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.